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 com.sun.org.apache.xml.internal.serializer;
  20. import java.util.Properties;
  21. /**
  22. * This class contains some static methods that act as helpers when parsing a
  23. * Java Property object.
  24. *
  25. * @see java.util.Properties
  26. */
  27. public class OutputPropertyUtils
  28. {
  29. /**
  30. * Searches for the boolean property with the specified key in the property list.
  31. * If the key is not found in this property list, the default property list,
  32. * and its defaults, recursively, are then checked. The method returns
  33. * <code>false</code> if the property is not found, or if the value is other
  34. * than "yes".
  35. *
  36. * @param key the property key.
  37. * @param props the list of properties that will be searched.
  38. * @return the value in this property list as a boolean value, or false
  39. * if null or not "yes".
  40. */
  41. public static boolean getBooleanProperty(String key, Properties props)
  42. {
  43. String s = props.getProperty(key);
  44. if (null == s || !s.equals("yes"))
  45. return false;
  46. else
  47. return true;
  48. }
  49. /**
  50. * Searches for the int property with the specified key in the property list.
  51. * If the key is not found in this property list, the default property list,
  52. * and its defaults, recursively, are then checked. The method returns
  53. * <code>false</code> if the property is not found, or if the value is other
  54. * than "yes".
  55. *
  56. * @param key the property key.
  57. * @param props the list of properties that will be searched.
  58. * @return the value in this property list as a int value, or 0
  59. * if null or not a number.
  60. */
  61. public static int getIntProperty(String key, Properties props)
  62. {
  63. String s = props.getProperty(key);
  64. if (null == s)
  65. return 0;
  66. else
  67. return Integer.parseInt(s);
  68. }
  69. }