View Javadoc

1   /*
2    * $Id: MessageResourcesConfig.java 421119 2006-07-12 04:49:11Z wsmoak $
3    *
4    * Copyright 1999-2005 The Apache Software Foundation.
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   *      http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  package org.apache.struts.config;
19  
20  import org.apache.struts.Globals;
21  
22  /***
23   * <p>A JavaBean representing the configuration information of a
24   * <code>&lt;message-resources&gt;</code> element in a Struts configuration
25   * file.</p>
26   *
27   * @version $Rev: 421119 $ $Date: 2005-08-29 23:57:50 -0400 (Mon, 29 Aug 2005)
28   *          $
29   * @since Struts 1.1
30   */
31  public class MessageResourcesConfig extends BaseConfig {
32      // ------------------------------------------------------------- Properties
33  
34      /***
35       * Fully qualified Java class name of the MessageResourcesFactory class we
36       * should use.
37       */
38      protected String factory =
39          "org.apache.struts.util.PropertyMessageResourcesFactory";
40  
41      /***
42       * The servlet context attributes key under which this MessageResources
43       * instance is stored.
44       */
45      protected String key = Globals.MESSAGES_KEY;
46  
47      /***
48       * Should we return <code>null</code> for unknown message keys?
49       */
50      protected boolean nullValue = true;
51  
52      /***
53       * Indicates whether 'escape processing' should be performed on the error
54       * message string.
55       */
56      private boolean escape = true;
57  
58      /***
59       * Parameter that is passed to the <code>createResources()</code> method
60       * of our MessageResourcesFactory implementation.
61       */
62      protected String parameter = null;
63  
64      public String getFactory() {
65          return (this.factory);
66      }
67  
68      public void setFactory(String factory) {
69          if (configured) {
70              throw new IllegalStateException("Configuration is frozen");
71          }
72  
73          this.factory = factory;
74      }
75  
76      public String getKey() {
77          return (this.key);
78      }
79  
80      public void setKey(String key) {
81          if (configured) {
82              throw new IllegalStateException("Configuration is frozen");
83          }
84  
85          this.key = key;
86      }
87  
88      public boolean getNull() {
89          return (this.nullValue);
90      }
91  
92      public void setNull(boolean nullValue) {
93          if (configured) {
94              throw new IllegalStateException("Configuration is frozen");
95          }
96  
97          this.nullValue = nullValue;
98      }
99  
100     /***
101      * Indicates whether 'escape processing' should be performed on the error
102      * message string.
103      *
104      * @since Struts 1.2.8
105      */
106     public boolean isEscape() {
107         return escape;
108     }
109 
110     /***
111      * Set whether 'escape processing' should be performed on the error
112      * message string.
113      *
114      * @since Struts 1.2.8
115      */
116     public void setEscape(boolean escape) {
117         this.escape = escape;
118     }
119 
120     public String getParameter() {
121         return (this.parameter);
122     }
123 
124     public void setParameter(String parameter) {
125         if (configured) {
126             throw new IllegalStateException("Configuration is frozen");
127         }
128 
129         this.parameter = parameter;
130     }
131 
132     // --------------------------------------------------------- Public Methods
133 
134     /***
135      * Return a String representation of this object.
136      */
137     public String toString() {
138         StringBuffer sb = new StringBuffer("MessageResourcesConfig[");
139 
140         sb.append("factory=");
141         sb.append(this.factory);
142         sb.append(",null=");
143         sb.append(this.nullValue);
144         sb.append(",escape=");
145         sb.append(this.escape);
146         sb.append(",parameter=");
147         sb.append(this.parameter);
148         sb.append("]");
149 
150         return (sb.toString());
151     }
152 }