KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > xml > serializer > OutputPropertyUtils


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

16 /*
17  * $Id: OutputPropertyUtils.java,v 1.2 2004/02/17 04:18:18 minchau Exp $
18  */

19 package org.apache.xml.serializer;
20
21 import java.util.Properties JavaDoc;
22
23 /**
24  * This class contains some static methods that act as helpers when parsing a
25  * Java Property object.
26  *
27  * @see java.util.Properties
28  */

29 public class OutputPropertyUtils
30 {
31     /**
32       * Searches for the boolean property with the specified key in the property list.
33       * If the key is not found in this property list, the default property list,
34       * and its defaults, recursively, are then checked. The method returns
35       * <code>false</code> if the property is not found, or if the value is other
36       * than "yes".
37       *
38       * @param key the property key.
39       * @param props the list of properties that will be searched.
40       * @return the value in this property list as a boolean value, or false
41       * if null or not "yes".
42       */

43     public static boolean getBooleanProperty(String JavaDoc key, Properties JavaDoc props)
44     {
45
46         String JavaDoc s = props.getProperty(key);
47
48         if (null == s || !s.equals("yes"))
49             return false;
50         else
51             return true;
52     }
53
54     /**
55      * Searches for the int property with the specified key in the property list.
56      * If the key is not found in this property list, the default property list,
57      * and its defaults, recursively, are then checked. The method returns
58      * <code>false</code> if the property is not found, or if the value is other
59      * than "yes".
60      *
61      * @param key the property key.
62      * @param props the list of properties that will be searched.
63      * @return the value in this property list as a int value, or 0
64      * if null or not a number.
65      */

66     public static int getIntProperty(String JavaDoc key, Properties JavaDoc props)
67     {
68
69         String JavaDoc s = props.getProperty(key);
70
71         if (null == s)
72             return 0;
73         else
74             return Integer.parseInt(s);
75     }
76
77 }
78
Popular Tags