| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| FormMessage |
|
| 1.0909090909090908;1,091 |
| 1 | package org.apache.turbine.util; | |
| 2 | ||
| 3 | ||
| 4 | /* | |
| 5 | * Licensed to the Apache Software Foundation (ASF) under one | |
| 6 | * or more contributor license agreements. See the NOTICE file | |
| 7 | * distributed with this work for additional information | |
| 8 | * regarding copyright ownership. The ASF licenses this file | |
| 9 | * to you under the Apache License, Version 2.0 (the | |
| 10 | * "License"); you may not use this file except in compliance | |
| 11 | * with the License. You may obtain a copy of the License at | |
| 12 | * | |
| 13 | * http://www.apache.org/licenses/LICENSE-2.0 | |
| 14 | * | |
| 15 | * Unless required by applicable law or agreed to in writing, | |
| 16 | * software distributed under the License is distributed on an | |
| 17 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | |
| 18 | * KIND, either express or implied. See the License for the | |
| 19 | * specific language governing permissions and limitations | |
| 20 | * under the License. | |
| 21 | */ | |
| 22 | ||
| 23 | ||
| 24 | import java.util.Vector; | |
| 25 | ||
| 26 | /** | |
| 27 | * A message class for holding information about a message that | |
| 28 | * relates to a specific form and field. Used together with | |
| 29 | * FormMessages class. | |
| 30 | * | |
| 31 | * @author <a href="mailto:neeme@one.lv">Neeme Praks</a> | |
| 32 | * @version $Id: FormMessage.java 1709648 2015-10-20 17:08:10Z tv $ | |
| 33 | */ | |
| 34 | public class FormMessage | |
| 35 | { | |
| 36 | private String message; | |
| 37 | private String formName; | |
| 38 | private final Vector<String> fieldNames; | |
| 39 | ||
| 40 | /** | |
| 41 | * Constructor. | |
| 42 | */ | |
| 43 | public FormMessage() | |
| 44 | 2 | { |
| 45 | 2 | fieldNames = new Vector<String>(); |
| 46 | 2 | } |
| 47 | ||
| 48 | /** | |
| 49 | * Constructor. | |
| 50 | * | |
| 51 | * @param formName A String with the form name. | |
| 52 | */ | |
| 53 | public FormMessage(String formName) | |
| 54 | { | |
| 55 | 2 | this(); |
| 56 | 2 | setFormName(formName); |
| 57 | 2 | } |
| 58 | ||
| 59 | /** | |
| 60 | * Constructor. | |
| 61 | * | |
| 62 | * @param formName A String with the form name. | |
| 63 | * @param fieldName A String with the field name. | |
| 64 | */ | |
| 65 | public FormMessage(String formName, | |
| 66 | String fieldName) | |
| 67 | { | |
| 68 | 2 | this(formName); |
| 69 | 2 | setFieldName(fieldName); |
| 70 | 2 | } |
| 71 | ||
| 72 | /** | |
| 73 | * Constructor. | |
| 74 | * | |
| 75 | * @param formName A String with the form name. | |
| 76 | * @param fieldName A String with the field name. | |
| 77 | * @param message A String with the message. | |
| 78 | */ | |
| 79 | public FormMessage(String formName, | |
| 80 | String fieldName, | |
| 81 | String message) | |
| 82 | { | |
| 83 | 2 | this(formName, fieldName); |
| 84 | 2 | setMessage(message); |
| 85 | 2 | } |
| 86 | ||
| 87 | /** | |
| 88 | * Return the message. | |
| 89 | * | |
| 90 | * @return A String with the message. | |
| 91 | */ | |
| 92 | public String getMessage() | |
| 93 | { | |
| 94 | 2 | return message; |
| 95 | } | |
| 96 | ||
| 97 | /** | |
| 98 | * Return the form name. | |
| 99 | * | |
| 100 | * @return A String with the form name. | |
| 101 | */ | |
| 102 | public String getFormName() | |
| 103 | { | |
| 104 | 2 | return formName; |
| 105 | } | |
| 106 | ||
| 107 | /** | |
| 108 | * Return the field names. | |
| 109 | * | |
| 110 | * @return A String[] with the field names. | |
| 111 | */ | |
| 112 | public String[] getFieldNames() | |
| 113 | { | |
| 114 | 8 | String[] result = new String[fieldNames.size()]; |
| 115 | 8 | fieldNames.copyInto(result); |
| 116 | 8 | return result; |
| 117 | } | |
| 118 | ||
| 119 | /** | |
| 120 | * Set the message. | |
| 121 | * | |
| 122 | * @param message A String with the message. | |
| 123 | */ | |
| 124 | public void setMessage(String message) | |
| 125 | { | |
| 126 | 2 | this.message = message; |
| 127 | 2 | } |
| 128 | ||
| 129 | /** | |
| 130 | * Set the form name. | |
| 131 | * | |
| 132 | * @param formName A String with the form name. | |
| 133 | */ | |
| 134 | public void setFormName(String formName) | |
| 135 | { | |
| 136 | 2 | this.formName = formName; |
| 137 | 2 | } |
| 138 | ||
| 139 | /** | |
| 140 | * Adds one field name. | |
| 141 | * | |
| 142 | * @param fieldName A String with the field name. | |
| 143 | */ | |
| 144 | public void setFieldName(String fieldName) | |
| 145 | { | |
| 146 | 3 | fieldNames.addElement(fieldName); |
| 147 | 3 | } |
| 148 | ||
| 149 | /** | |
| 150 | * Write out the contents of the message in a friendly manner. | |
| 151 | * | |
| 152 | */ | |
| 153 | @Override | |
| 154 | public String toString() | |
| 155 | { | |
| 156 | 2 | StringBuilder sb = new StringBuilder("formName:" + getFormName() + ", fieldNames:"); |
| 157 | 5 | for (int i = 0; i< getFieldNames().length; i++){ |
| 158 | 3 | sb.append(getFieldNames()[i] + " "); |
| 159 | } | |
| 160 | 2 | sb.append(", message:" + getMessage()); |
| 161 | ||
| 162 | 2 | return sb.toString(); |
| 163 | } | |
| 164 | } |