KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > infoglue > cms > util > ChainedStringManager


1 /* ===============================================================================
2  *
3  * Part of the InfoGlue Content Management Platform (www.infoglue.org)
4  *
5  * ===============================================================================
6  *
7  * Copyright (C)
8  *
9  * This program is free software; you can redistribute it and/or modify it under
10  * the terms of the GNU General Public License version 2, as published by the
11  * Free Software Foundation. See the file LICENSE.html for more information.
12  *
13  * This program is distributed in the hope that it will be useful, but WITHOUT
14  * ANY WARRANTY, including the implied warranty of MERCHANTABILITY or FITNESS
15  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along with
18  * this program; if not, write to the Free Software Foundation, Inc. / 59 Temple
19  * Place, Suite 330 / Boston, MA 02111-1307 / USA.
20  *
21  * ===============================================================================
22  */

23
24 package org.infoglue.cms.util;
25
26 import java.text.MessageFormat JavaDoc;
27 import java.util.ArrayList JavaDoc;
28 import java.util.Iterator JavaDoc;
29 import java.util.List JavaDoc;
30
31 import org.infoglue.cms.exception.Bug;
32 import org.infoglue.cms.exception.ConfigurationError;
33
34
35 /**
36  *
37  */

38 class ChainedStringManager implements StringManager {
39   // --- [Constants] -----------------------------------------------------------
40
// --- [Attributes] ----------------------------------------------------------
41

42   //
43
private List JavaDoc managers = new ArrayList JavaDoc();
44
45
46
47   // --- [Static] --------------------------------------------------------------
48

49   // The string manager for this package.
50
private static final StringManager sm = StringManagerFactory.getSystemStringManager(Constants.PACKAGE_NAME);
51
52
53
54   // --- [Constructors] --------------------------------------------------------
55
// --- [Public] --------------------------------------------------------------
56
// --- [org.infoglue.cms.util.StringManager implementation] -----------------
57

58   /**
59    *
60    */

61   public final String JavaDoc getString(String JavaDoc key) {
62     for(Iterator JavaDoc iterator = this.managers.iterator(); iterator.hasNext(); ) {
63       SimpleStringManager manager = (SimpleStringManager) iterator.next();
64       if(manager.containsKey(key)) {
65         return manager.getString(key);
66       }
67     }
68     throw new ConfigurationError(sm.getString("chain.getString.not_found_error", key));
69   }
70
71   /**
72    *
73    */

74   public final String JavaDoc getString(String JavaDoc key, Object JavaDoc args[]) {
75     return MessageFormat.format(getString(key), args);
76   }
77
78   /**
79    *
80    */

81   public final String JavaDoc getString(String JavaDoc key, Object JavaDoc arg) {
82     return getString(key, new Object JavaDoc[]{ arg });
83   }
84
85   /**
86    *
87    */

88   public final String JavaDoc getString(String JavaDoc key, Object JavaDoc arg1, Object JavaDoc arg2) {
89     return getString(key, new Object JavaDoc[]{ arg1, arg2 });
90   }
91
92   /**
93    *
94    */

95   public final String JavaDoc getString(String JavaDoc key, Object JavaDoc arg1, Object JavaDoc arg2, Object JavaDoc arg3) {
96     return getString(key, new Object JavaDoc[]{ arg1, arg2, arg3 });
97   }
98
99
100
101   // --- [X Overrides] ---------------------------------------------------------
102
// --- [Package protected] ---------------------------------------------------
103

104   /**
105    *
106    */

107   final void add(StringManager manager) {
108     if(manager == null) {
109       throw new Bug(sm.getString("chain.add.null_parameter_error"));
110     }
111     this.managers.add(manager);
112   }
113
114
115
116   // --- [Private] -------------------------------------------------------------
117
// --- [Protected] -----------------------------------------------------------
118
// --- [Inner classes] -------------------------------------------------------
119
}
120
Popular Tags