Redirect Tomcat ROOT index.html to your site app

If I have a app at https://abc.com/server/client.html, I want to redirect traffic going to https://abc.com to the same app and not the default Tomcat root page.

Put this in the …/webaps/ROOT/index.html

<html>
<head>
<meta http-equiv=”refresh” content=”0;URL=http[s]://abc.com/server/client.html”>
</head>
<body>
</body>
</html>

Advertisements

Flex DateTimeValidator

I wrote the first version of a Date & Time validator for Flex. This version extends DateValidator and adds optional time. At the moment the time format is fixed to HH:MM:SS using “:” separator. I may update this later.

Enjoy



package com.helper
{
import mx.validators.DateValidator;
import mx.validators.ValidationResult;
import mx.validators.Validator;
public class DateTimeValidator extends DateValidator
{
// Define Array for the return value of doValidation().
private var results:Array;
private var timeArray:Array = new Array();
public static const RANGE_ERROR:String = “RangeError”;
public static const FORMAT_ERROR:String = “FormatError”;
public static const MAX_EXCEEDED_ERROR:String = “MaxValueExceeded”;
public static const MIN_EXCEEDED_ERROR:String = “MinValuesExceeded”;
public static const INVALID_HOUR_ERROR:String = “INVALID_HOUR_ERROR”;
public static const INVALID_MIN_ERROR:String = “INVALID_MIN_ERROR”;
public static const INVALID_SEC_ERROR:String = “INVALID_SEC_ERROR”;
public static const INVALID_TIME_ERROR:String = “INVALID_TIME_ERROR”;
public static const INVALID_SEPARATOR_ERROR:String = “INVALID_SEPARATOR_ERROR”;
private var _wrongHour:String;
private var _wrongMinute:String;
private var _wrongSecond:String;
public function DateTimeValidator()
{
super();
}
// Define the doValidation() method.
override protected function doValidation(value:Object):Array
{
var dateTimeArray:Array = new Array();
// Clear results Array.
results = [];
var dateString:String = String(value);
// Assume Date is now DATE[ TIME]
dateTimeArray = String(dateString).split(” “);
if(dateTimeArray.length > 0 && String(dateTimeArray[0]).length != 0)
{
// Call the parent Date Validator to validate the date part
results = super.doValidation(dateTimeArray[0]);
}
// Return if there are errors.
if (results.length > 0)
{
return results;
}
// Now validate the time part if there is one
if(dateTimeArray.length > 1)
{
// Expecting HH:MM:SS String. Split the String
timeArray = String(dateTimeArray[1]).split(“:”);
if(timeArray.length == 3)
{
var hour:int = Number(timeArray[0]);
var minute:int = Number(timeArray[1]);
var second:int = Number(timeArray[2]);
/////
// Now check the hour values
if(hour >= 0 && hour <= 23)
{
} else {
results.push(new ValidationResult(true,”hour”,RANGE_ERROR,”Hours need to be between 00 and 23″));
}
// Now check the minute values
if(minute >= 0 && minute <= 59)
{
} else {
results.push(new ValidationResult(true,”minute”,RANGE_ERROR,”Minutes need to be between 00 and 59″));
}
// Now check the minute values
if(second >= 0 && second <= 59)
{
} else {
results.push(new ValidationResult(true,”second”,RANGE_ERROR,”Seconds need to be between 00 and 59″));
}
} else {
results.push(new ValidationResult(true,”format”, FORMAT_ERROR, “Please enter the time as HH:MM:SS”));
}
}
// Return if there are errors.
if (results.length > 0)
{
return results;
}
return results;
}
}
}
And just for kicks, here is the FlexUnit testing of the code:
package com.helper
{
import com.helper.DateTimeValidator;
import flexunit.framework.Assert;
import mx.events.ValidationResultEvent;
public class DateTimeValidatorTests
{
private var fixture:DateTimeValidator
[Before]
public function runBeforeEveryTest():void
{
fixture = new DateTimeValidator();
fixture.inputFormat =  “YYYY/MM/DD”;
fixture.allowedFormatChars = “/-.”;
}
[After]
public function runAfterEveryTest():void
{
fixture = null;
}
[Test]
public function formatDateTimeTests():void
{
fixture.inputFormat = “YYYY/MM/DD”;
Assert.assertEquals(“2010/12/31 00:00:00”, ValidationResultEvent.VALID, fixture.validate(“2010/12/31 00:00:00”).type);
Assert.assertEquals(“31/12/2010 00:00:00”, ValidationResultEvent.INVALID, fixture.validate(“31/12/2010 00:00:00”).type);
Assert.assertEquals(“12/31/2010 00:00:00”, ValidationResultEvent.INVALID, fixture.validate(“12/31/2010 00:00:00”).type);
fixture.inputFormat = “DD/MM/YYYY”;
Assert.assertEquals(“2010/12/31 00:00:00”, ValidationResultEvent.INVALID, fixture.validate(“2010/12/31 00:00:00”).type);
Assert.assertEquals(“31/12/2010 00:00:00”, ValidationResultEvent.VALID, fixture.validate(“31/12/2010 00:00:00”).type);
Assert.assertEquals(“12/31/2010 00:00:00”, ValidationResultEvent.INVALID, fixture.validate(“12/31/2010 00:00:00”).type);
fixture.inputFormat = “MM/DD/YYYY”;
Assert.assertEquals(“2010/12/31 00:00:00”, ValidationResultEvent.INVALID, fixture.validate(“2010/12/31 00:00:00”).type);
Assert.assertEquals(“31/12/2010 00:00:00”, ValidationResultEvent.INVALID, fixture.validate(“31/12/2010 00:00:00”).type);
Assert.assertEquals(“12/31/2010 00:00:00”, ValidationResultEvent.VALID, fixture.validate(“12/31/2010 00:00:00”).type);
}
[Test]
public function validDateTimeTests():void
{
Assert.assertEquals(“2010/12/31”, ValidationResultEvent.VALID, fixture.validate(“2010/12/31”).type);
Assert.assertEquals(“2010-12-31”, ValidationResultEvent.VALID, fixture.validate(“2010-12-31”).type);
Assert.assertEquals(“2010.12.31”, ValidationResultEvent.VALID, fixture.validate(“2010.12.31”).type);
Assert.assertEquals(“2010/12/31 00:00:00”, ValidationResultEvent.VALID, fixture.validate(“2010/12/31 00:00:00”).type);
Assert.assertEquals(“2010/12/31 23:59:59”, ValidationResultEvent.VALID, fixture.validate(“2010/12/31 23:59:59”).type);
Assert.assertEquals(“2010/12/31 01:09:09”, ValidationResultEvent.VALID, fixture.validate(“2010/12/31 01:09:09”).type);
Assert.assertEquals(“2010/12/31 2:3:4”, ValidationResultEvent.VALID, fixture.validate(“2010/12/31 2:3:4”).type);
}
[Test]
public function invalidDateTimeTests():void
{
Assert.assertEquals(“99/12/31”, ValidationResultEvent.INVALID, fixture.validate(“99/12/31”).type);
Assert.assertEquals(“12/31”, ValidationResultEvent.INVALID, fixture.validate(“12/31”).type);
Assert.assertEquals(“31”, ValidationResultEvent.INVALID, fixture.validate(“31”).type);
Assert.assertEquals(“2010/22/31”, ValidationResultEvent.INVALID, fixture.validate(“2010/22/31”).type);
Assert.assertEquals(“2010/12/55”, ValidationResultEvent.INVALID, fixture.validate(“2010/12/55”).type);
Assert.assertEquals(“-2010/12/31”, ValidationResultEvent.INVALID, fixture.validate(“-2010/12/31”).type);
Assert.assertEquals(“2010/-12/31”, ValidationResultEvent.INVALID, fixture.validate(“2010/-12/31”).type);
Assert.assertEquals(“2010/12/-31”, ValidationResultEvent.INVALID, fixture.validate(“2010/12/-31”).type);
Assert.assertEquals(“2010/12/31 -1:00:00”, ValidationResultEvent.INVALID, fixture.validate(“2010/12/31 -1:00:00”).type);
Assert.assertEquals(“2010/12/31 00:-1:00”, ValidationResultEvent.INVALID, fixture.validate(“2010/12/31 00:-1:00”).type);
Assert.assertEquals(“2010/12/31 00:00:-1”, ValidationResultEvent.INVALID, fixture.validate(“2010/12/31 00:-1:00”).type);
Assert.assertEquals(“2010/12/31 00:00”, ValidationResultEvent.INVALID, fixture.validate(“2010/12/31 00:00”).type);
Assert.assertEquals(“2010/12/31 00”, ValidationResultEvent.INVALID, fixture.validate(“2010/12/31 00”).type);
Assert.assertEquals(“2010/12/31 25:00:00”, ValidationResultEvent.INVALID, fixture.validate(“2010/12/31 25:00:00”).type);
Assert.assertEquals(“2010/12/31 00:60:00”, ValidationResultEvent.INVALID, fixture.validate(“2010/12/31 00:60:00”).type);
Assert.assertEquals(“2010/12/31 00:00:60”, ValidationResultEvent.INVALID, fixture.validate(“2010/12/31 00:00:60”).type);
Assert.assertEquals(“2010/12/31 25:60:60”, ValidationResultEvent.INVALID, fixture.validate(“2010/12/31 25:60:60”).type);
Assert.assertEquals(“2010/12/31 00:00 AM”, ValidationResultEvent.INVALID, fixture.validate(“2010/12/31 00:00 AM”).type);
Assert.assertEquals(“2010/12/31 00:00 PM”, ValidationResultEvent.INVALID, fixture.validate(“2010/12/31 00:00 PM”).type);
Assert.assertEquals(“2010/12/31 3654567”, ValidationResultEvent.INVALID, fixture.validate(“2010/12/31 3654567”).type);
Assert.assertEquals(3654567, ValidationResultEvent.INVALID, fixture.validate(3654567).type);
}
}
}