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