Subversion Repository Public Repository

litesoft

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package com.temp.common.shared.validators;

import org.litesoft.externalization.shared.*;

import com.temp.common.shared.*;
import com.temp.common.shared.utils.*;

public class MaxLengthValueValidator implements ValueValidator {
    public static final String TEMPLATE_ID_CODE = "TooLong";
    public static final String USER_DATA_MAX_LENGTH = "maxLength";
    public static final String USER_DATA_CURRENT_LENGTH = "currentLength";

    private final int maxLength;

    public MaxLengthValueValidator( int maxLength ) {
        this.maxLength = Validate.length( "maxLength", maxLength );
    }

    @Override
    public E13nData checkValue( Object value ) {
        if ( value instanceof String ) {
            return checkString( value.toString().trim() );
        }
        return null; // OK!
    }

    protected E13nData checkString( String userData ) {
        if ( userData.length() > maxLength ) {
            return E13nData.builder( TEMPLATE_ID_CODE )//
                    .addSubstitutionNamedUserData( USER_DATA_MAX_LENGTH, Integer.toString( maxLength ) ) //
                    .addSubstitutionNamedUserData( USER_DATA_CURRENT_LENGTH, Integer.toString( userData.length() ) )
                    .build();
        }
        return null; // OK!
    }
}

Commits for litesoft/trunk/GWT_Sandbox/FormEngine/src/com/temp/common/shared/validators/MaxLengthValueValidator.java

Diff revisions: vs.
Revision Author Commited Message
964 GeorgeS picture GeorgeS Fri 01 Aug, 2014 03:18:23 +0000

!