You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

LoadableProperties.java 2.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*
  2. * $Id$
  3. * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
  4. * For details on use and redistribution please refer to the
  5. * LICENSE file included with these sources.
  6. */
  7. package org.apache.fop.viewer;
  8. import java.io.*;
  9. import java.util.*;
  10. /**
  11. * Erweitert Hashtable um die Methode load.
  12. * Die Zeilen der Textdatei, die mit # oder ! anfangen sind Kommentarzeilen.
  13. * Eine gültige Zeile ist entweder eine Kommentarzeile oder eine Zeile mit dem
  14. * Gleichheitszeichen "in der Mitte".
  15. * Die Klasse LoadableProperties lässt im Gegensatz zu der Klasse Properties die
  16. * Schlüsselwerte mit Leerzeichen zu.
  17. *
  18. * @version 02.12.99
  19. * @author Stanislav.Gorkhover@jCatalog.com
  20. *
  21. */
  22. public class LoadableProperties extends Hashtable {
  23. public LoadableProperties() {
  24. super();
  25. }
  26. public void load(InputStream inStream) throws IOException {
  27. BufferedReader in = new BufferedReader(new InputStreamReader(inStream,
  28. "8859_1"));
  29. String aKey;
  30. String aValue;
  31. int index;
  32. String line = getNextLine(in);
  33. while (line != null) {
  34. line = line.trim();
  35. if (isValid(line)) {
  36. index = line.indexOf("=");
  37. aKey = line.substring(0, index);
  38. aValue = line.substring(index + 1);
  39. put(aKey, aValue);
  40. }
  41. line = getNextLine(in);
  42. }
  43. }
  44. private boolean isValid(String str) {
  45. if (str == null)
  46. return false;
  47. if (str.length() > 0) {
  48. if (str.startsWith("#") || str.startsWith("!")) {
  49. return false;
  50. }
  51. } else {
  52. return false;
  53. }
  54. int index = str.indexOf("=");
  55. if (index > 0 && str.length() > index) {
  56. return true;
  57. } else {
  58. //log.debug(getClass().getName()
  59. // + ": load(): invalid line " + str + "."
  60. // + " Character '=' missed.");
  61. return false;
  62. }
  63. }
  64. private String getNextLine(BufferedReader br) {
  65. try {
  66. return br.readLine();
  67. } catch (Exception e) {
  68. return null;
  69. }
  70. }
  71. }