01: /**
02: * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE, version 2.1, dated February 1999.
03: *
04: * This program is free software; you can redistribute it and/or modify
05: * it under the terms of the latest version of the GNU Lesser General
06: * Public License as published by the Free Software Foundation;
07: *
08: * This program is distributed in the hope that it will be useful,
09: * but WITHOUT ANY WARRANTY; without even the implied warranty of
10: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11: * GNU Lesser General Public License for more details.
12: *
13: * You should have received a copy of the GNU Lesser General Public License
14: * along with this program (LICENSE.txt); if not, write to the Free Software
15: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16: */package org.jamwiki.utils;
17:
18: import java.util.Collections;
19: import java.util.Enumeration;
20: import java.util.Properties;
21: import java.util.Vector;
22:
23: /**
24: * This class acts as a utility class for providing the capability of a property file
25: * that is sorted alphabetically by key value. It is useful for things like translation
26: * files where having the file in a logical order is useful for maintainers.
27: */
28: public class SortedProperties extends Properties {
29:
30: /** Logger */
31: public static final WikiLogger logger = WikiLogger
32: .getLogger(SortedProperties.class.getName());
33:
34: /**
35: * Standard constructor for creating a sorted properties file.
36: */
37: public SortedProperties() {
38: super ();
39: }
40:
41: /**
42: * Copy constructor used to create a sorted properties file.
43: */
44: public SortedProperties(Properties properties) {
45: super ();
46: this .putAll(properties);
47: }
48:
49: /**
50: * Override the Properties.keys() method so that the keyset returned is sorted.
51: */
52: public Enumeration keys() {
53: Enumeration keyEnum = super .keys();
54: Vector keys = new Vector();
55: while (keyEnum.hasMoreElements()) {
56: keys.add(keyEnum.nextElement());
57: }
58: Collections.sort(keys);
59: return keys.elements();
60: }
61: }
|