ValidationUtils { public static boolean bboxIsValid( String bbox ) { if ( bbox == null || bbox.trim().isEmpty() ) { return false; } Matcher matcher = BBOX_PATTERN.matcher( bbox ); if ( !matcher.matches() ) { return false; } double minLng = Double.parseDouble( matcher.group( 1 ) ); double minLat = Double.parseDouble( matcher.group( 4 ) ); double maxLng = Double.parseDouble( matcher.group( 7 ) ); double maxLat = Double.parseDouble( matcher.group( 10 ) ); if ( minLng < -180d || minLng > 180d || maxLng < -180d || maxLng > 180d ) { return false; } if ( minLat < -90d || minLat > 90d || maxLat < -90d || maxLat > 90d ) { return false; } return true; }  static boolean expressionIsValidSQl( String filter ); static boolean emailIsValid( String email ); static boolean dateIsValid( String date, Locale locale ); static boolean dateIsValid( String date ); static boolean timeIsValid( String time ); static boolean urlIsValid( String url ); static boolean uuidIsValid( String uuid ); static boolean usernameIsValid( String username ); static boolean passwordIsValid( String password ); static boolean coordinateIsValid( String coordinate ); static boolean bboxIsValid( String bbox ); static String getLongitude( String coordinate ); static String getLatitude( String coordinate ); static Point2D getCoordinatePoint2D( String coordinate ); static String getCoordinate( String longitude, String latitude ); static String dataValueIsValid( String value, DataElement dataElement ); static String dataValueIsValid( String value, ValueType valueType ); static boolean dataValueIsZeroAndInsignificant( String value, DataElement dataElement ); static String commentIsValid( String comment ); static String storedByIsValid( String storedBy ); static boolean isValidHexColor( String value ); static Object getSubstitutionValue( ValueType valueType ); static String normalizeBoolean( String bool, ValueType valueType ); static boolean validateRenderingType( Class<?> clazz, ValueType valueType, boolean optionSet, ValueTypeRenderingType type ); static boolean validateWhatsapp( String whatsapp ); static boolean validateInternationalPhoneNumber( String phoneNumber ); static final ImmutableSet<String> ILLEGAL_SQL_KEYWORDS; }
@Test public void testBboxIsValid() { assertTrue( bboxIsValid( "-13.2682125,7.3721619,-10.4261178,9.904012" ) ); assertTrue( bboxIsValid( "12.26821,-23.3721,13.4261,-21.904" ) ); assertTrue( bboxIsValid( "4,-23.37,5,-24.904" ) ); assertTrue( bboxIsValid( "2.23, -23.37, 5.22, -24.90" ) ); assertTrue( bboxIsValid( "-179.234,-89.342,178.323,88.135" ) ); assertFalse( bboxIsValid( "[12.23,14.41,34.12,12.45]" ) ); assertFalse( bboxIsValid( "22,23,14,41,34,11,11,41" ) ); assertFalse( bboxIsValid( "22,23.14,41.34,11.11,41" ) ); assertFalse( bboxIsValid( "-181.234,-89.342,178.323,88.135" ) ); assertFalse( bboxIsValid( "-179.234,-92.342,178.323,88.135" ) ); assertFalse( bboxIsValid( "-179.234,-89.342,185.323,88.135" ) ); assertFalse( bboxIsValid( "-179.234,-89.342,178.323,94.135" ) ); }