001/* 002 Licensed to the Apache Software Foundation (ASF) under one 003 or more contributor license agreements. See the NOTICE file 004 distributed with this work for additional information 005 regarding copyright ownership. The ASF licenses this file 006 to you under the Apache License, Version 2.0 (the 007 "License"); you may not use this file except in compliance 008 with the License. You may obtain a copy of the License at 009 010 http://www.apache.org/licenses/LICENSE-2.0 011 012 Unless required by applicable law or agreed to in writing, 013 software distributed under the License is distributed on an 014 "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 KIND, either express or implied. See the License for the 016 specific language governing permissions and limitations 017 under the License. 018 */ 019package org.apache.wiki.forms; 020 021import java.io.Serializable; 022import java.util.HashMap; 023import java.util.Map; 024 025/** 026 * Container for carrying HTTP FORM information between Plugin invocations in the Session. 027 */ 028public class FormInfo implements Serializable { 029 030 private static final long serialVersionUID = 0L; 031 032 /** 033 * State: Form is executed. 034 */ 035 public static final int EXECUTED = 1; 036 037 /** 038 * State: Form is OK. 039 */ 040 public static final int OK = 0; 041 042 /** 043 * State: There was an error. 044 */ 045 public static final int ERROR = -1; 046 047 private int m_status; 048 private boolean m_hide; 049 private String m_action; 050 private String m_name; 051 private String m_handler; 052 private String m_result; 053 private String m_error; 054 private Map<String, String> m_submission; 055 056 /** 057 * Creates a new FormInfo with status == OK. 058 */ 059 public FormInfo() { 060 m_status = OK; 061 } 062 063 /** 064 * Set the status of the Form processing. 065 * 066 * @param val EXECUTED, OK or ERROR. 067 */ 068 public void setStatus( final int val) { 069 m_status = val; 070 } 071 072 /** 073 * Return the status. 074 * 075 * @return The status. 076 */ 077 public int getStatus() { 078 return m_status; 079 } 080 081 /** 082 * Set the hide parameter. 083 * 084 * @param val True or false. 085 */ 086 public void setHide( final boolean val) { 087 m_hide = val; 088 } 089 090 /** 091 * Returns true, if the form is supposed to be hidden. 092 * 093 * @return True or false. 094 */ 095 public boolean hide() { 096 return m_hide; 097 } 098 099 /** 100 * Set the value of the action parameter. 101 * 102 * @param val A value parameter. 103 */ 104 public void setAction( final String val) { 105 m_action = val; 106 } 107 108 /** 109 * Get the action set in {@link #setAction(String)}. 110 * 111 * @return An Action. 112 */ 113 public String getAction() { 114 return m_action; 115 } 116 117 /** 118 * Sets the name of the form. 119 * 120 * @param val The name of the form. 121 */ 122 public void setName( final String val) { 123 m_name = val; 124 } 125 126 /** 127 * Return the name of the form. 128 * 129 * @return The name of the form. 130 */ 131 public String getName() { 132 return m_name; 133 } 134 135 /** 136 * Set the name of the handler class. 137 * 138 * @param val The name of the class. 139 */ 140 public void setHandler( final String val) { 141 m_handler = val; 142 } 143 144 /** 145 * Return the name of the handler class. 146 * 147 * @return The name of the class. 148 */ 149 public String getHandler() { 150 return m_handler; 151 } 152 153 /** 154 * Set the result. 155 * 156 * @param val The result. 157 */ 158 public void setResult( final String val) { 159 m_result = val; 160 } 161 162 /** 163 * Return the result. 164 * 165 * @return The result. 166 */ 167 public String getResult() { 168 return m_result; 169 } 170 171 /** 172 * Set an error string. 173 * 174 * @param val An error string. 175 */ 176 public void setError( final String val) { 177 m_error = val; 178 } 179 180 /** 181 * Return the error. 182 * 183 * @return The error. 184 */ 185 public String getError() { 186 return m_error; 187 } 188 189 /** 190 * Copies the given values into the handler parameter map using Map.putAll(). 191 * 192 * @param val parameter name-value pairs for a Form handler WikiPlugin 193 */ 194 public void setSubmission( final Map<String, String> val) { 195 m_submission = new HashMap<>(); 196 m_submission.putAll(val); 197 } 198 199 /** 200 * Adds the given values into the handler parameter map. 201 * 202 * @param val parameter name-value pairs for a Form handler WikiPlugin 203 */ 204 public void addSubmission( final Map<String, String> val) { 205 if (m_submission == null) { 206 m_submission = new HashMap<>(); 207 } 208 m_submission.putAll(val); 209 } 210 211 /** 212 * Returns parameter name-value pairs for a Form handler WikiPlugin. 213 * The names are those of Form input fields, and the values whatever 214 * the user selected in the form. The FormSet plugin can also be used 215 * to provide initial values. 216 * 217 * @return Handler parameter name-value pairs. 218 */ 219 public Map<String, String> getSubmission() { 220 return m_submission; 221 } 222}