001 /* 002 * Copyright 2002-2006 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); you may not 005 * use this file except in compliance with the License. You may obtain a copy of 006 * the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 012 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 013 * License for the specific language governing permissions and limitations under 014 * the License. 015 */ 016 package org.springframework.binding.form.support; 017 018 import org.springframework.binding.form.FieldMetadata; 019 import org.springframework.binding.form.FormModel; 020 021 /** 022 * Class which holds keys for user metadata used in spring rich 023 * 024 * @author Mathias Broekelmann 025 * 026 */ 027 public abstract class UserMetadata { 028 /** 029 * The name of a user metadata value which is used to determine if a value for a form field is protected and should 030 * be hidden on logging or error messages. 031 * <p> 032 * The value must be an instance of {@link Boolean}, if true any value of the field will not be displayed either 033 * through logging or showing value errors 034 */ 035 public static final String PROTECTED_FIELD = "org.springframework.binding.support.ProtectedField"; 036 037 /** 038 * tests if the usermetadata of the field has a boolean value true for the key {@value #PROTECTED_FIELD} 039 * 040 * @param fieldName 041 * the fieldname 042 * @return true if the field is protected, otherwise false 043 */ 044 public static boolean isFieldProtected(FormModel formModel, String fieldName) { 045 FieldMetadata metaData = formModel.getFieldMetadata(fieldName); 046 return Boolean.TRUE.equals(metaData.getUserMetadata(UserMetadata.PROTECTED_FIELD)); 047 } 048 049 /** 050 * defines the protectable state for a field 051 * 052 * @param formModel the formmodel 053 * @param fieldName the field to protect 054 * @param protectedField if true the field will be defined as protectable otherwise false 055 */ 056 public static void setFieldProtected(FormModel formModel, String fieldName, boolean protectedField) { 057 FieldMetadata metaData = formModel.getFieldMetadata(fieldName); 058 metaData.getAllUserMetadata().put(PROTECTED_FIELD, Boolean.valueOf(protectedField)); 059 } 060 }