01: /*
02: * $Header: /cvsroot/jvalidate/jvalidate-framework/jvalidate/src/main/java/nl/knowlogy/validation/validators/IsNotBlankValidator.java,v 1.6 2007/06/20 16:24:56 roberthofstra Exp $
03: * $Revision: 1.6 $
04: * $Date: 2007/06/20 16:24:56 $
05: *
06: *
07: * Created on Oct 6, 2004
08: *
09: * All right reserved(c) 2004, Knowlogy
10: *
11: * Copyright 2004 - 2005 Knowlogy, the Netherlands. All rights reserved.
12: * All Knowlogy brand and product names are trademarks or registered trademarks
13: * of Knowlogy in the Netherlands and other countries.
14: *
15: * No part of this publication may be reproduced, transmitted, stored in a retrieval system,
16: * or translated into any human or computer language, in any form, or by any means, electronic,
17: * mechanical, magnetic, optical, chemical, manual, or otherwise,
18: * without the prior written permission of the copyright owner, Knowlogy.
19: *
20: */
21: package nl.knowlogy.validation.validators;
22:
23: import nl.knowlogy.validation.ErrorCodes;
24: import nl.knowlogy.validation.MessageType;
25: import nl.knowlogy.validation.Messages;
26: import nl.knowlogy.validation.PropertyMetadataSuplier;
27: import nl.knowlogy.validation.metadata.PropertyMetadata;
28:
29: import org.apache.commons.lang.StringUtils;
30:
31: /**
32: *
33: * @author Robert
34: */
35: public class IsNotBlankValidator extends BasePropertyValidator
36: implements PropertyMetadataSuplier {
37:
38: /**
39: *
40: */
41: public IsNotBlankValidator(String propertyName) {
42: super (propertyName);
43: }
44:
45: public IsNotBlankValidator(String propertyName, String errorCode) {
46: this (propertyName);
47: setErrorCode(errorCode);
48: }
49:
50: /*
51: * (non-Javadoc)
52: *
53: * @see nl.knowlogy.validation.metadata.PropertyValidation#doValidatePropertyValue(java.lang.Object,
54: * nl.knowlogy.validation.errors.Errors)
55: */
56: public void doValidatePropertyValue(Object toValidate,
57: Object propertyValue, Messages errors) {
58: if (propertyValue != null) {
59: String stringValue = propertyValue.toString();
60: if (StringUtils.isBlank(stringValue)) {
61: errors.addPropertyMessage(MessageType.ERROR,
62: toValidate, getPropertyName(), getErrorCode());
63: }
64: } else {
65: errors.addPropertyMessage(MessageType.ERROR, toValidate,
66: getPropertyName(), getErrorCode());
67: }
68:
69: }
70:
71: public String getDefaultErrorCode() {
72: return ErrorCodes.ISNOTBLANK;
73: }
74:
75: public String toString() {
76: return "IsNotBlankValidator, " + super .toString();
77: }
78:
79: public void supplyMetaData(PropertyMetadata propertyMetadata) {
80: propertyMetadata.setRequired(Boolean.TRUE);
81: }
82: }
|