01: /*
02: * Copyright 1999-2004 The Apache Software Foundation.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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.4 2005/04/07 04:29:03 minchau Exp $
18: */
19: package org.apache.xml.serializer;
20:
21: import java.util.Properties;
22:
23: /**
24: * This class contains some static methods that act as helpers when parsing a
25: * Java Property object.
26: *
27: * This class is not a public API.
28: * It is only public because it is used outside of this package.
29: *
30: * @see java.util.Properties
31: * @xsl.usage internal
32: */
33: public final class OutputPropertyUtils {
34: /**
35: * Searches for the boolean property with the specified key in the property list.
36: * If the key is not found in this property list, the default property list,
37: * and its defaults, recursively, are then checked. The method returns
38: * <code>false</code> if the property is not found, or if the value is other
39: * than "yes".
40: *
41: * @param key the property key.
42: * @param props the list of properties that will be searched.
43: * @return the value in this property list as a boolean value, or false
44: * if null or not "yes".
45: */
46: public static boolean getBooleanProperty(String key,
47: Properties props) {
48:
49: String s = props.getProperty(key);
50:
51: if (null == s || !s.equals("yes"))
52: return false;
53: else
54: return true;
55: }
56:
57: /**
58: * Searches for the int property with the specified key in the property list.
59: * If the key is not found in this property list, the default property list,
60: * and its defaults, recursively, are then checked. The method returns
61: * <code>false</code> if the property is not found, or if the value is other
62: * than "yes".
63: *
64: * @param key the property key.
65: * @param props the list of properties that will be searched.
66: * @return the value in this property list as a int value, or 0
67: * if null or not a number.
68: */
69: public static int getIntProperty(String key, Properties props) {
70:
71: String s = props.getProperty(key);
72:
73: if (null == s)
74: return 0;
75: else
76: return Integer.parseInt(s);
77: }
78:
79: }
|