View Javadoc

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