1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 package integration.forms;
24 
25 import com.sun.star.form.binding.*;
26 
27 /**
28  *
29  * @author  fs@openoffice.org
30  */
31 public class TextValidator extends integration.forms.ControlValidator
32 {
33 
34     /** Creates a new instance of NumericValidator */
TextValidator( )35     public TextValidator( )
36     {
37     }
38 
explainInvalid( Object Value )39     public String explainInvalid( Object Value )
40     {
41         try
42         {
43             String value = (String)Value;
44             if ( containsZs( value ) )
45                 return "No Z's allowed here";
46             if ( !isProperChunks( value ) )
47                 return "Need 3 * n characters";
48         }
49         catch( java.lang.Exception e )
50         {
51             return "ooops. Unknown error";
52         }
53         return "";
54     }
55 
isValid( Object Value )56     public boolean isValid( Object Value )
57     {
58         try
59         {
60             String value = (String)Value;
61             if ( containsZs( value ) )
62                 return false;
63             if ( !isProperChunks( value ) )
64                 return false;
65             return true;
66         }
67         catch( java.lang.Exception e )
68         {
69         }
70         return false;
71     }
72 
isProperChunks( String value )73     private boolean isProperChunks( String value )
74     {
75         return ( value.length() % 3 ) == 0;
76     }
77 
containsZs( String value )78     private boolean containsZs( String value )
79     {
80         if  (  ( value.indexOf( 'Z' ) != -1 )
81             || ( value.indexOf( 'z' ) != -1 )
82             )
83             return true;
84         return false;
85     }
86 }
87