OutputPropertyUtils.java revision 9f8118474e9513f7a5b7d2a05e4a0fb15d1a6569
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the  "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 *     http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18/*
19 * $Id: OutputPropertyUtils.java 468654 2006-10-28 07:09:23Z minchau $
20 */
21package org.apache.xml.serializer;
22
23import java.util.Properties;
24
25/**
26 * This class contains some static methods that act as helpers when parsing a
27 * Java Property object.
28 *
29 * This class is not a public API.
30 * It is only public because it is used outside of this package.
31 *
32 * @see java.util.Properties
33 * @xsl.usage internal
34 */
35public final class OutputPropertyUtils
36{
37    /**
38      * Searches for the boolean property with the specified key in the property list.
39      * If the key is not found in this property list, the default property list,
40      * and its defaults, recursively, are then checked. The method returns
41      * <code>false</code> if the property is not found, or if the value is other
42      * than "yes".
43      *
44      * @param   key   the property key.
45      * @param   props   the list of properties that will be searched.
46      * @return  the value in this property list as a boolean value, or false
47      * if null or not "yes".
48      */
49    public static boolean getBooleanProperty(String key, Properties props)
50    {
51
52        String s = props.getProperty(key);
53
54        if (null == s || !s.equals("yes"))
55            return false;
56        else
57            return true;
58    }
59
60    /**
61     * Searches for the int property with the specified key in the property list.
62     * If the key is not found in this property list, the default property list,
63     * and its defaults, recursively, are then checked. The method returns
64     * <code>false</code> if the property is not found, or if the value is other
65     * than "yes".
66     *
67     * @param   key   the property key.
68     * @param   props   the list of properties that will be searched.
69     * @return  the value in this property list as a int value, or 0
70     * if null or not a number.
71     */
72    public static int getIntProperty(String key, Properties props)
73    {
74
75        String s = props.getProperty(key);
76
77        if (null == s)
78            return 0;
79        else
80            return Integer.parseInt(s);
81    }
82
83}
84