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$ 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 { 44 fieldNames = new ArrayList<>(); 45 } 46 47 /** 48 * Constructor. 49 * 50 * @param formName A String with the form name. 51 */ 52 public FormMessage(String formName) 53 { 54 this(); 55 setFormName(formName); 56 } 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 this(formName); 68 setFieldName(fieldName); 69 } 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 this(formName, fieldName); 83 setMessage(message); 84 } 85 86 /** 87 * Return the message. 88 * 89 * @return A String with the message. 90 */ 91 public String getMessage() 92 { 93 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 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 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 this.message = message; 124 } 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 this.formName = formName; 134 } 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 fieldNames.add(fieldName); 144 } 145 146 /** 147 * Write out the contents of the message in a friendly manner. 148 * 149 */ 150 @Override 151 public String toString() 152 { 153 StringBuilder sb = new StringBuilder("formName:" + getFormName() + ", fieldNames:"); 154 for (int i = 0; i< getFieldNames().length; i++){ 155 sb.append(getFieldNames()[i] + " "); 156 } 157 sb.append(", message:" + getMessage()); 158 159 return sb.toString(); 160 } 161 }