PageRenderTime 40ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/bundles/plugins-trunk/XML/xml/gui/PropertyUtil.java

#
Java | 83 lines | 27 code | 9 blank | 47 comment | 4 complexity | 51c189affd16054df48adc79c2480222 MD5 | raw file
Possible License(s): BSD-3-Clause, AGPL-1.0, Apache-2.0, LGPL-2.0, LGPL-3.0, GPL-2.0, CC-BY-SA-3.0, LGPL-2.1, GPL-3.0, MPL-2.0-no-copyleft-exception, IPL-1.0
  1. /*
  2. * PropertyUtil.java - Utility methods for accessing properties
  3. *
  4. * Copyright 2002 Greg Merrill
  5. * 2004 Robert McKinnon
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License
  9. * as published by the Free Software Foundation; either version 2
  10. * of the License, or any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  20. */
  21. package xml.gui;
  22. import org.gjt.sp.jedit.jEdit;
  23. import java.util.ArrayList;
  24. import java.util.List;
  25. /**
  26. * Utility methods for accessing properties.
  27. * copied from XSLTPlugin: xslt/PropertyUtil.java
  28. * @author Greg Merrill
  29. * @author Robert McKinnon
  30. */
  31. public class PropertyUtil {
  32. /**
  33. * Returns a List of property values whose keys are identical excepct for
  34. * a trailing "." and index.
  35. *
  36. * @param key key of the enumerated property, excluding the trailing "." and
  37. * index. I.e., if you have properties "file.0=file0.txt" and
  38. * "file.1=file1.txt", calling getEnumeratedProperty("file", properties)
  39. * would return a list containing "file0.txt" and "file1.txt".
  40. */
  41. public static List<String> getEnumeratedProperty(String key) {
  42. List<String> values = new ArrayList<String>();
  43. int i = 0;
  44. String value;
  45. while ((value = jEdit.getProperty(calculateKey(key, i++))) != null) {
  46. values.add(value);
  47. }
  48. return values;
  49. }
  50. /**
  51. * Sets a series of property values whose keys are identical excepct for
  52. * a trailing "." and index.
  53. *
  54. * @param key key of the enumerated property (see
  55. * {@link #getEnumeratedProperty})
  56. * @param values values to be assigned to the enumerated property, in order.
  57. * All members of this List must be Strings.
  58. */
  59. public static void setEnumeratedProperty(String key, List<String> values) {
  60. List currentValues = getEnumeratedProperty(key);
  61. for (int i = 0; i < currentValues.size(); i++) {
  62. jEdit.setProperty(calculateKey(key, i), null);
  63. }
  64. for (int i = 0; i < values.size(); i++) {
  65. jEdit.setProperty(calculateKey(key, i), values.get(i));
  66. }
  67. }
  68. /**
  69. * @return indexed property key
  70. */
  71. private static String calculateKey(String key, int index) {
  72. return key + "." + index;
  73. }
  74. }