01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: *
17: */
18: package org.apache.lenya.cms.usecase;
19:
20: import org.apache.lenya.util.Assert;
21:
22: /**
23: * A message in a usecase. This an encapsulation for an internationalizable
24: * message, containing a message content and potentially some parameters. The
25: * parameters correspond to the placeholders in dictionary entries.
26: *
27: * @version $Id: UsecaseMessage.java 571600 2007-08-31 21:40:20Z rfrovarp $
28: */
29: public class UsecaseMessage {
30:
31: private String message;
32: private String[] params;
33:
34: /**
35: * Ctor.
36: * @param _message The message.
37: */
38: public UsecaseMessage(String _message) {
39: Assert.notNull("message", _message);
40: this .message = _message;
41: }
42:
43: /**
44: * Ctor.
45: * @param _message The message.
46: * @param _params The parameters.
47: */
48: public UsecaseMessage(String _message, String[] _params) {
49: this (_message);
50:
51: Assert.notNull("params", _params);
52: for (int i = 0; i < _params.length; i++) {
53: Assert.notNull("params[" + i + "]", _params[i]);
54: }
55: this .params = (String[]) _params.clone();
56: }
57:
58: /**
59: * Determine if this message has parameters
60: * @return true if the message has parameters
61: */
62: public boolean hasParameters() {
63: return params != null && params.length > 0;
64: }
65:
66: /**
67: * Retrieve the message content
68: * @return the message
69: */
70: public String getMessage() {
71: return message;
72: }
73:
74: /**
75: * Returns the parameters of this message. If no parameters are set,
76: * an empty String array is returned.
77: * @return the parameters
78: */
79: public String[] getParameters() {
80: return this .params == null ? new String[0] : this .params;
81: }
82:
83: /**
84: * @return A string representation, the parameters are included as a comma-separated list.
85: */
86: public String toString() {
87: StringBuffer msg = new StringBuffer(getMessage());
88: String[] params = getParameters();
89: for (int i = 0; i < params.length; i++) {
90: msg.append(", " + params[i]);
91: }
92: return msg.toString();
93: }
94: }
|