Version 6.1.0.2, tag libreoffice-6.1.0.2
[LibreOffice.git] / odk / examples / DevelopersGuide / Forms / TimeValidator.java
blobd5f1503d8cb1a7bb39e3c82bc740c0937f1c300a
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 TimeValidator extends ControlValidator
24 /** Creates a new instance of NumericValidator */
25 public TimeValidator( )
29 public String explainInvalid( Object Value )
31 try
33 if ( isVoid( Value ) )
34 return "empty input";
36 com.sun.star.util.Time timeValue = (com.sun.star.util.Time)Value;
37 if ( isInvalidTime( timeValue ) )
38 return "this is no valid time";
39 if ( !isFullHour( timeValue ) )
40 return "time must denote a full hour";
42 catch( java.lang.Exception e )
44 return "this is no valid time";
46 return "";
49 public boolean isValid( Object Value )
51 try
53 if ( isVoid( Value ) )
54 return false;
56 com.sun.star.util.Time timeValue = (com.sun.star.util.Time)
57 com.sun.star.uno.AnyConverter.toObject(
58 com.sun.star.util.Time.class, Value);
59 if ( isInvalidTime( timeValue ) )
60 return false;
61 if ( !isFullHour( timeValue ) )
62 return false;
63 return true;
65 catch( java.lang.Exception e )
67 e.printStackTrace( System.err );
69 return false;
72 private boolean isInvalidTime( com.sun.star.util.Time timeValue )
74 return ( timeValue.Hours == -1 ) && ( timeValue.Minutes == -1 ) && ( timeValue.Seconds == -1 ) && ( timeValue.NanoSeconds == -1 );
77 private boolean isFullHour( com.sun.star.util.Time timeValue )
79 return ( timeValue.Minutes == 0 ) && ( timeValue.Seconds == 0 ) && ( timeValue.NanoSeconds == 0 );
83 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */