001 // Copyright 2005 The Apache Software Foundation 002 // 003 // Licensed under the Apache License, Version 2.0 (the "License"); 004 // you may not use this file except in compliance with the License. 005 // You may obtain a copy of the License at 006 // 007 // http://www.apache.org/licenses/LICENSE-2.0 008 // 009 // Unless required by applicable law or agreed to in writing, software 010 // distributed under the License is distributed on an "AS IS" BASIS, 011 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 012 // See the License for the specific language governing permissions and 013 // limitations under the License. 014 015 package org.apache.tapestry.form; 016 017 import java.util.List; 018 019 import org.apache.tapestry.IMarkupWriter; 020 import org.apache.tapestry.IRender; 021 import org.apache.tapestry.IRequestCycle; 022 import org.apache.tapestry.valid.IFieldTracking; 023 import org.apache.tapestry.valid.IValidationDelegate; 024 import org.apache.tapestry.valid.IValidator; 025 import org.apache.tapestry.valid.ValidationConstraint; 026 import org.apache.tapestry.valid.ValidatorException; 027 028 /** 029 * Mock implementation of {@link org.apache.tapestry.valid.IValidationDelegate} used for testing 030 * (particularily, to test how the delegate decorates fields and field labels. 031 * 032 * @author Howard M. Lewis Ship 033 * @since 4.0 034 */ 035 public class MockDelegate implements IValidationDelegate 036 { 037 private static final long serialVersionUID = -1940135823929783031L; 038 039 private IFormComponent _component; 040 041 private String _input; 042 043 private boolean _inError; 044 045 public void registerForFocus(IFormComponent field, int priority) 046 { 047 } 048 049 public MockDelegate() 050 { 051 this(false); 052 } 053 054 public MockDelegate(boolean inError) 055 { 056 _inError = inError; 057 } 058 059 public IFormComponent getFormComponent() 060 { 061 return _component; 062 } 063 064 public void setFormComponent(IFormComponent component) 065 { 066 _component = component; 067 } 068 069 public boolean isInError() 070 { 071 return _inError; 072 } 073 074 public String getFieldInputValue() 075 { 076 return _input; 077 } 078 079 public List getFieldTracking() 080 { 081 return null; 082 } 083 084 public void reset() 085 { 086 } 087 088 public void clear() 089 { 090 } 091 092 public void recordFieldInputValue(String input) 093 { 094 _input = input; 095 } 096 097 public void record(ValidatorException ex) 098 { 099 } 100 101 public void record(String message, ValidationConstraint constraint) 102 { 103 } 104 105 public void record(IRender errorRenderer, ValidationConstraint constraint) 106 { 107 } 108 109 public void writePrefix(IMarkupWriter writer, IRequestCycle cycle, IFormComponent component, 110 IValidator validator) 111 { 112 writer.begin("span"); 113 writer.attribute("class", "prefix"); 114 } 115 116 public void writeAttributes(IMarkupWriter writer, IRequestCycle cycle, 117 IFormComponent component, IValidator validator) 118 { 119 writer.attribute("class", "validation-delegate"); 120 } 121 122 public void writeSuffix(IMarkupWriter writer, IRequestCycle cycle, IFormComponent component, 123 IValidator validator) 124 { 125 writer.end(); 126 } 127 128 public void beforeLabelText(IMarkupWriter writer, IRequestCycle cycle, IFormComponent component) 129 { 130 } 131 132 public void afterLabelText(IMarkupWriter writer, IRequestCycle cycle, IFormComponent component) 133 { 134 } 135 136 public void writeLabelPrefix(IFormComponent component, IMarkupWriter writer, IRequestCycle cycle) 137 { 138 } 139 140 public void writeLabelAttributes(IMarkupWriter writer, IRequestCycle cycle, IFormComponent component) 141 { 142 } 143 144 public void writeLabelSuffix(IFormComponent component, IMarkupWriter writer, IRequestCycle cycle) 145 { 146 } 147 148 public boolean getHasErrors() 149 { 150 return false; 151 } 152 153 public IFieldTracking getCurrentFieldTracking() 154 { 155 return null; 156 } 157 158 public List getErrorRenderers() 159 { 160 return null; 161 } 162 163 public String getFocusField() 164 { 165 return null; 166 } 167 168 public void clearErrors() 169 { 170 } 171 172 public void record(IFormComponent field, String message) 173 { 174 // TODO Auto-generated method stub 175 176 } 177 178 }