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