Version 6.1.0.2, tag libreoffice-6.1.0.2
[LibreOffice.git] / odk / examples / DevelopersGuide / Forms / TextValidator.java
blob241bd8778cd20fc52f6253125951eb2dfa001e9e
1 /* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 public class TextValidator extends ControlValidator
24 /** Creates a new instance of NumericValidator */
25 public TextValidator( )
29 public String explainInvalid( Object Value )
31 try
33 String value = (String)Value;
34 if ( containsZs( value ) )
35 return "No Z's allowed here";
36 if ( !isProperChunks( value ) )
37 return "Need 3 * n characters";
39 catch( java.lang.Exception e )
41 return "ooops. Unknown error";
43 return "";
46 public boolean isValid( Object Value )
48 try
50 String value = (String)Value;
51 if ( containsZs( value ) )
52 return false;
53 if ( !isProperChunks( value ) )
54 return false;
55 return true;
57 catch( java.lang.Exception e )
60 return false;
63 private boolean isProperChunks( String value )
65 return ( value.length() % 3 ) == 0;
68 private boolean containsZs( String value )
70 if ( ( value.indexOf( 'Z' ) != -1 )
71 || ( value.indexOf( 'z' ) != -1 )
73 return true;
74 return false;
78 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */