Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
FormMessage |
|
| 1.0909090909090908;1,091 |
1 | package org.apache.turbine.util; | |
2 | ||
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 | ||
22 | import java.util.ArrayList; | |
23 | import java.util.List; | |
24 | ||
25 | /** | |
26 | * A message class for holding information about a message that | |
27 | * relates to a specific form and field. Used together with | |
28 | * FormMessages class. | |
29 | * | |
30 | * @author <a href="mailto:neeme@one.lv">Neeme Praks</a> | |
31 | * @version $Id: FormMessage.java 1838127 2018-08-15 17:59:03Z tv $ | |
32 | */ | |
33 | public class FormMessage | |
34 | { | |
35 | private String message; | |
36 | private String formName; | |
37 | private final List<String> fieldNames; | |
38 | ||
39 | /** | |
40 | * Constructor. | |
41 | */ | |
42 | public FormMessage() | |
43 | 6 | { |
44 | 6 | fieldNames = new ArrayList<String>(); |
45 | 6 | } |
46 | ||
47 | /** | |
48 | * Constructor. | |
49 | * | |
50 | * @param formName A String with the form name. | |
51 | */ | |
52 | public FormMessage(String formName) | |
53 | { | |
54 | 6 | this(); |
55 | 6 | setFormName(formName); |
56 | 6 | } |
57 | ||
58 | /** | |
59 | * Constructor. | |
60 | * | |
61 | * @param formName A String with the form name. | |
62 | * @param fieldName A String with the field name. | |
63 | */ | |
64 | public FormMessage(String formName, | |
65 | String fieldName) | |
66 | { | |
67 | 6 | this(formName); |
68 | 6 | setFieldName(fieldName); |
69 | 6 | } |
70 | ||
71 | /** | |
72 | * Constructor. | |
73 | * | |
74 | * @param formName A String with the form name. | |
75 | * @param fieldName A String with the field name. | |
76 | * @param message A String with the message. | |
77 | */ | |
78 | public FormMessage(String formName, | |
79 | String fieldName, | |
80 | String message) | |
81 | { | |
82 | 6 | this(formName, fieldName); |
83 | 6 | setMessage(message); |
84 | 6 | } |
85 | ||
86 | /** | |
87 | * Return the message. | |
88 | * | |
89 | * @return A String with the message. | |
90 | */ | |
91 | public String getMessage() | |
92 | { | |
93 | 6 | return message; |
94 | } | |
95 | ||
96 | /** | |
97 | * Return the form name. | |
98 | * | |
99 | * @return A String with the form name. | |
100 | */ | |
101 | public String getFormName() | |
102 | { | |
103 | 6 | return formName; |
104 | } | |
105 | ||
106 | /** | |
107 | * Return the field names. | |
108 | * | |
109 | * @return A String[] with the field names. | |
110 | */ | |
111 | public String[] getFieldNames() | |
112 | { | |
113 | 24 | return fieldNames.toArray(new String[fieldNames.size()]); |
114 | } | |
115 | ||
116 | /** | |
117 | * Set the message. | |
118 | * | |
119 | * @param message A String with the message. | |
120 | */ | |
121 | public void setMessage(String message) | |
122 | { | |
123 | 6 | this.message = message; |
124 | 6 | } |
125 | ||
126 | /** | |
127 | * Set the form name. | |
128 | * | |
129 | * @param formName A String with the form name. | |
130 | */ | |
131 | public void setFormName(String formName) | |
132 | { | |
133 | 6 | this.formName = formName; |
134 | 6 | } |
135 | ||
136 | /** | |
137 | * Adds one field name. | |
138 | * | |
139 | * @param fieldName A String with the field name. | |
140 | */ | |
141 | public void setFieldName(String fieldName) | |
142 | { | |
143 | 9 | fieldNames.add(fieldName); |
144 | 9 | } |
145 | ||
146 | /** | |
147 | * Write out the contents of the message in a friendly manner. | |
148 | * | |
149 | */ | |
150 | @Override | |
151 | public String toString() | |
152 | { | |
153 | 6 | StringBuilder sb = new StringBuilder("formName:" + getFormName() + ", fieldNames:"); |
154 | 15 | for (int i = 0; i< getFieldNames().length; i++){ |
155 | 9 | sb.append(getFieldNames()[i] + " "); |
156 | } | |
157 | 6 | sb.append(", message:" + getMessage()); |
158 | ||
159 | 6 | return sb.toString(); |
160 | } | |
161 | } |