}
}
private void addCommonAttributes(final FieldMetadata field,
final Element fieldElement) {
AnnotationMetadata annotationMetadata;
if (field.getFieldType().equals(INT_OBJECT)
|| field.getFieldType().getFullyQualifiedTypeName()
.equals(int.class.getName())
|| field.getFieldType().equals(SHORT_OBJECT)
|| field.getFieldType().getFullyQualifiedTypeName()
.equals(short.class.getName())
|| field.getFieldType().equals(LONG_OBJECT)
|| field.getFieldType().getFullyQualifiedTypeName()
.equals(long.class.getName())
|| field.getFieldType().equals(BIG_INTEGER)) {
fieldElement.setAttribute("validationMessageCode",
"field_invalid_integer");
}
else if (isEmailField(field)) {
fieldElement.setAttribute("validationMessageCode",
"field_invalid_email");
}
else if (field.getFieldType().equals(DOUBLE_OBJECT)
|| field.getFieldType().getFullyQualifiedTypeName()
.equals(double.class.getName())
|| field.getFieldType().equals(FLOAT_OBJECT)
|| field.getFieldType().getFullyQualifiedTypeName()
.equals(float.class.getName())
|| field.getFieldType().equals(BIG_DECIMAL)) {
fieldElement.setAttribute("validationMessageCode",
"field_invalid_number");
}
if ("field:input".equals(fieldElement.getTagName())
&& null != (annotationMetadata = MemberFindingUtils
.getAnnotationOfType(field.getAnnotations(), MIN))) {
final AnnotationAttributeValue<?> min = annotationMetadata
.getAttribute(VALUE);
if (min != null) {
fieldElement.setAttribute("min", min.getValue().toString());
fieldElement.setAttribute("required", "true");
}
}
if ("field:input".equals(fieldElement.getTagName())
&& null != (annotationMetadata = MemberFindingUtils
.getAnnotationOfType(field.getAnnotations(), MAX))
&& !"field:textarea".equals(fieldElement.getTagName())) {
final AnnotationAttributeValue<?> maxA = annotationMetadata
.getAttribute(VALUE);
if (maxA != null) {
fieldElement.setAttribute("max", maxA.getValue().toString());
}
}
if ("field:input".equals(fieldElement.getTagName())
&& null != (annotationMetadata = MemberFindingUtils
.getAnnotationOfType(field.getAnnotations(),
DECIMAL_MIN))
&& !"field:textarea".equals(fieldElement.getTagName())) {
final AnnotationAttributeValue<?> decimalMin = annotationMetadata
.getAttribute(VALUE);
if (decimalMin != null) {
fieldElement.setAttribute("decimalMin", decimalMin.getValue()
.toString());
fieldElement.setAttribute("required", "true");
}
}
if ("field:input".equals(fieldElement.getTagName())
&& null != (annotationMetadata = MemberFindingUtils
.getAnnotationOfType(field.getAnnotations(),
DECIMAL_MAX))) {
final AnnotationAttributeValue<?> decimalMax = annotationMetadata
.getAttribute(VALUE);
if (decimalMax != null) {
fieldElement.setAttribute("decimalMax", decimalMax.getValue()
.toString());
}
}
if (null != (annotationMetadata = MemberFindingUtils
.getAnnotationOfType(field.getAnnotations(), PATTERN))) {
final AnnotationAttributeValue<?> regexp = annotationMetadata
.getAttribute(new JavaSymbolName("regexp"));
if (regexp != null) {
fieldElement.setAttribute("validationRegex", regexp.getValue()
.toString());
}
}
if ("field:input".equals(fieldElement.getTagName())
&& null != (annotationMetadata = MemberFindingUtils
.getAnnotationOfType(field.getAnnotations(), SIZE))) {
final AnnotationAttributeValue<?> max = annotationMetadata
.getAttribute(new JavaSymbolName("max"));
if (max != null) {
fieldElement.setAttribute("max", max.getValue().toString());
}
final AnnotationAttributeValue<?> min = annotationMetadata
.getAttribute(new JavaSymbolName("min"));
if (min != null) {
fieldElement.setAttribute("min", min.getValue().toString());
fieldElement.setAttribute("required", "true");
}