<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <!-- * +-------------------------------------------------------------------------+ * | jsPro - Validator Test Page | * +-------------------------------------------------------------------------+ * | Copyright (C) 2001-2003 Stuart Wigley | * +-------------------------------------------------------------------------+ * | This library is free software; you can redistribute it and/or modify it | * | under the terms of the GNU Lesser General Public License as published by| * | the Free Software Foundation; either version 2.1 of the License, or (at | * | your option) any later version. | * | | * | This library is distributed in the hope that it will be useful, but | * | WITHOUT ANY WARRANTY; without even the implied warranty of | * | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser | * | General Public License for more details. | * | | * | You should have received a copy of the GNU Lesser General Public License| * | along with this library; if not, write to the Free Software Foundation, | * | Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | * +-------------------------------------------------------------------------+ * | Authors: Stuart Wigley <stuartwigley@yahoo.co.uk> | * +-------------------------------------------------------------------------+ * $Id: validator.html,v 1.1 2003/09/19 15:42:46 wigleys Exp $ --> <html> <head> <title>jsPro - Validator</title> <!-- error.js --> <script type="text/javascript"> /** * +-------------------------------------------------------------------------+ * | jsPro - Error | * +-------------------------------------------------------------------------+ * | Copyright (C) 2001-2003 Stuart Wigley | * +-------------------------------------------------------------------------+ * | This library is free software; you can redistribute it and/or modify it | * | under the terms of the GNU Lesser General Public License as published by| * | the Free Software Foundation; either version 2.1 of the License, or (at | * | your option) any later version. | * | | * | This library is distributed in the hope that it will be useful, but | * | WITHOUT ANY WARRANTY; without even the implied warranty of | * | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser | * | General Public License for more details. | * | | * | You should have received a copy of the GNU Lesser General Public License| * | along with this library; if not, write to the Free Software Foundation, | * | Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | * +-------------------------------------------------------------------------+ * | Authors: Stuart Wigley <stuartwigley@yahoo.co.uk> | * | Randolph Fielding <gator4life@cinci.rr.com> | * +-------------------------------------------------------------------------+ * $Id: error.js,v 1.15 2003/09/22 04:41:10 gator4life Exp $ */
/** * Property used in <code>Error.handleError</code> to specify how errors are * reported. Permissable values are: * * 0 No errors are reported. * 1 Report the error name and error message using the status bar of the * active browser window. * 2 Report the error name and error message using an alert box. * 3 Report the error name, error message and debug message using an alert * box. * 4 Report the error name, error message and debug message using a debug * window. An instance of the Debug() class must be available. */ Error.prototype.debugLevel = 4;
/** * Uses <code>Error.debugLevel</code> to control how errors are reported. If * <code>Error.debugLevel</code> is set to 4, you must substitute the name of * your <code>Debug()</code> instance for <code>oDebug</code> in the line * <code>var jsProDebugWindow = oDebug</code>. * * @summary handles thrown exceptions * @author Stuart Wigley * @author Randolph Fielding * @version 1.2, 09/03/03 * @interface <code>Error.handleError()</code> * @requires <code>Debug.print(vMixedValue, sMessageType)</code> * @see <code>Debug()</code> * @see <code>Debug.print()</code> */ Error.prototype.handleError = function() {
var sDebugMessage = this.debug; var sErrorMessage = (sDebugMessage) ? sDebugMessage : '';
switch (this.debugLevel) { case 0 : break; case 1 : window.status = this.name + ': ' + this.message; break; case 2 : window.alert(this.name + 'nn' + this.message); break; case 3 : window.alert(this.name + 'nn' + this.message + 'nn' + sErrorMessage); break; case 4 : var jsProDebugWindow = oDebug; if (jsProDebugWindow) { var oDebugWindow = jsProDebugWindow.debugWindow; if (oDebugWindow && !oDebugWindow.closed) { jsProDebugWindow.print(this.name + ' ' + this.message + ' ' + sErrorMessage, 1); } } } }
/** * Creates an object that is a subclass of Error for handling * ArrayIndexOutOfBounds exceptions. * * @author Stuart Wigley * @author Randolph Fielding * @version 1.1, 06/27/03 * @interface <code>new ArrayIndexOutOfBoundsException(sMethodName, * iIndex, iArrayLength)</code> * @param sMethodName the name of the method where the exception was thrown * @param iIndex the index of a hypothetical array member attempting to * be accessed * @param iArrayLength the length of the array */ function ArrayIndexOutOfBoundsException(sMethodName, iIndex, iArrayLength) {
this.name = 'ArrayIndexOutOfBoundsException'; this.message = sMethodName + ' has been accessed with an illegal index that is either negative or greater than the size of the array.'; this.debug = 'Attempting to access index ' + iIndex.toString() + ', but array has an index range of 0 to ' + (iArrayLength - 1).toString() + '.'; }
ArrayIndexOutOfBoundsException.prototype = new Error();
/** * Creates an object that is a subclass of Error for handling IllegalArgument * exceptions. * * @author Stuart Wigley * @author Randolph Fielding * @version 1.2, 07/24/03 * @interface <code>new IllegalArgumentException(sMethodName, * vExpectedArgs, iActualArgs)</code> * @param sMethodName the name of the method where the exception was thrown * @param vExpectedArgs the number of arguments expected * @param iActualArgs the number of arguments received */ function IllegalArgumentException(sMethodName, vExpectedArgs, iActualArgs) {
this.name = 'IllegalArgumentException'; this.message = sMethodName + ' has been passed an illegal number of arguments.'; this.debug = 'Expected ' + vExpectedArgs.toString() + ' argument(s), but received ' + iActualArgs.toString() + ' argument(s).'; }
IllegalArgumentException.prototype = new Error();
/** * Creates an object that is a subclass of Error for handling IllegalValue * exceptions. * * @author Randolph Fielding * @version 1.0, 09/22/03 * @interface <code>new IllegalValueException(sMethodName, * sVariableName, vExpectedVal, vActualVal)</code> * @param sMethodName the name of the method where the exception was thrown * @param sVariableName the name of the variable containing the illegal value * @param vExpectedVal the value expected in the variable containing the * illegal value * @param vActualVal the value currently in the variable containing the * illegal value */ function IllegalValueException(sMethodName, sVariableName, vExpectedVal, vActualVal) {
this.name = 'IllegalValueException'; this.message = sMethodName + ' has encountered an illegal value in variable ' + sVariableName + '.' this.debug = 'Expected a value of ' + vExpectedVal.toString() + ', but contains a value of ' + vActualVal.toString() + '.' }
IllegalValueException.prototype = new Error();
/** * Creates an object that is a subclass of Error for handling * MethodNotAvailable exceptions. * * @author Stuart Wigley * @author Randolph Fielding * @version 1.1, 06/27/03 * @interface <code>new MethodNotAvailableException(sMethodName, * sMethodNameNA)</code> * @param sMethodName the name of the method where the exception was thrown * @param sMethodNameNA the name of the method that was not available */ function MethodNotAvailableException(sMethodName, sMethodNameNA) {
this.name = 'MethodNotAvailableException'; this.message = 'A method has been called that is not available.'; this.debug = sMethodName + ' attempted to call ' + sMethodNameNA + '.'; }
MethodNotAvailableException.prototype = new Error();
/** * Creates an object that is a subclass of Error for handling * PropertyNotAvailable exceptions. * * @author Randolph Fielding * @version 1.1, 08/01/03 * @interface <code>new PropertyNotAvailableException(sMethodName, * sPropNameNA)</code> * @param sMethodName the name of the method where the exception was thrown * @param sPropNameNA the name of the property that was not available */ function PropertyNotAvailableException(sMethodName, sPropNameNA) {
this.name = 'PropertyNotAvailableException'; this.message = 'A property has been accessed that is not available.'; this.debug = sMethodName + ' attempted to access ' + sPropNameNA + '.'; }
PropertyNotAvailableException.prototype = new Error();
/** * Creates an object that is a subclass of Error for handling TypeMismatch * exceptions. * * @author Stuart Wigley * @author Randolph Fielding * @version 1.2, 07/24/03 * @interface <code>new TypeMismatchException(sMethodName, * sExpectedType, sActualType)</code> * @param sMethodName the name of the method where the exception was thrown * @param sExpectedType the name of the expected type of an argument * @param sActualType the name of the actual type of an argument */ function TypeMismatchException(sMethodName, sExpectedType, sActualType) {
this.name = 'TypeMismatchException'; this.message = sMethodName + ' has been passed an argument with an illegal or inappropriate type.'; this.debug = 'Expected an argument with a type of ' + sExpectedType + ', but received an argument with a type of ' + sActualType + '.'; }
TypeMismatchException.prototype = new Error();
/** * Creates an object that is a subclass of Error for handling Unknown * exceptions. * * @author Stuart Wigley * @author Randolph Fielding * @version 1.1, 06/27/03 * @interface <code>new UnknownException(sMethodName)</code> * @param sMethodName the name of the method where the exception was thrown */ function UnknownException(sMethodName) {
this.name = 'UnknownException'; this.message = 'An unknown error has occurred in ' + sMethodName + '.'; }
UnknownException.prototype = new Error(); </script> <!-- debug.js --> <script type="text/javascript"> /** * +-------------------------------------------------------------------------+ * | jsPro - Debug | * +-------------------------------------------------------------------------+ * | Copyright (C) 2001-2003 Stuart Wigley | * +-------------------------------------------------------------------------+ * | This library is free software; you can redistribute it and/or modify it | * | under the terms of the GNU Lesser General Public License as published by| * | the Free Software Foundation; either version 2.1 of the License, or (at | * | your option) any later version. | * | | * | This library is distributed in the hope that it will be useful, but | * | WITHOUT ANY WARRANTY; without even the implied warranty of | * | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser | * | General Public License for more details. | * | | * | You should have received a copy of the GNU Lesser General Public License| * | along with this library; if not, write to the Free Software Foundation, | * | Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | * +-------------------------------------------------------------------------+ * | Authors: Stuart Wigley <stuartwigley@yahoo.co.uk> | * | Randolph Fielding <gator4life@cinci.rr.com> | * +-------------------------------------------------------------------------+ * $Id: debug.js,v 1.6 2003/09/22 05:07:41 gator4life Exp $ */
/** * Creates an object that opens a window for debugging. * * @author Stuart Wigley * @author Randolph Fielding * @version 1.1, 09/05/03 * @interface <code>new Debug()</code> */ function Debug() {
this.debugWindow = window.open('../debug/debug.html', 'debug', 'width=400,height=600,resizable=yes,scrollbars=yes'); }
/** * Clears the contents of the debug window. * * @author Stuart Wigley * @author Randolph Fielding * @version 1.1, 09/05/03 * @interface <code>Debug.clear()</code> * @return <code>true</code> if no exceptions are encountered * @return <code>null</code> if an exception is encountered * @throws IllegalArgumentException * @throws UnknownException */ Debug.prototype.clear = function() {
try {
var vError = null; var iNumArguments = arguments.length;
if (iNumArguments != 0) { throw vError = new IllegalArgumentException('Debug.clear', 0, iNumArguments); }
var oMessageContainer = document.getElementById('messageContainer');
if (!oMessageContainer) { throw vError = new UnknownException('Debug.clear'); }
while (oMessageContainer.hasChildNodes()) { oMessageContainer.removeChild(oMessageContainer.firstChild); } } catch (vError) {
if (vError instanceof Error) { vError.handleError(); } } finally {
return vError ? null : true; } }
/** * Displays content within the debug window. * * @author Stuart Wigley * @author Randolph Fielding * @version 1.2, 09/05/03 * @interface <code>Debug.print(vMixedValue)</code> * @interface <code>Debug.print(vMixedValue, iMessageType)</code> * @param vMixedValue content to be displayed within the debug window * @param iMessageType an integer representing the type of content to display * within the debug window (information: 0; error: 1) * (optional) * @return <code>true</code> if no exceptions are encountered * @return <code>null</code> if an exception is encountered * @throws IllegalArgumentException * @throws IllegalValueException * @throws TypeMismatchException * @throws UnknownException */ Debug.prototype.print = function(vMixedValue) {
try {
var vError = null; var iNumArguments = arguments.length; var iMessageType = 0;
if ((iNumArguments < 1) || (iNumArguments > 2)) { throw vError = new IllegalArgumentException('Debug.print', '1 or 2', iNumArguments); } else if (iNumArguments == 2) { iMessageType = arguments[1]; }
if ((typeof iMessageType != 'number') || (iMessageType.toString().indexOf('.') != -1)) { throw vError = new TypeMismatchException('Debug.print', 'integer', typeof iMessageType); }
if ((iMessageType != 0) && (iMessageType != 1)) { throw vError = new IllegalValueException('Debug.print', 'iMessageType', '0 or 1', iMessageType); }
var oDebugWindow = this.debugWindow;
if (!oDebugWindow || oDebugWindow.closed) { throw vError = new UnknownException('Debug.print'); }
var oDocument = oDebugWindow.document;
if (!oDocument) { throw vError = new UnknownException('Debug.print'); }
var oMessageContainer = oDocument.getElementById('messageContainer');
if (!oMessageContainer) { throw vError = new UnknownException('Debug.print'); }
var oTitleRow = oDocument.createElement('tr'); var oTitleCell = oDocument.createElement('td'); var oBodyRow = oDocument.createElement('tr'); var oBodyCell = oDocument.createElement('td');
if (!oTitleRow || !oTitleCell || !oBodyRow || !oBodyCell) { throw vError = new UnknownException('Debug.print'); }
var oTitleRowStyle = oTitleRow.style;
if (oTitleRowStyle) { oTitleRowStyle.backgroundColor = '#EEE'; oTitleRowStyle.fontWeight = 700; }
var sOutputString = vMixedValue.toString(); var sTitle = 'info'; var sBody = sOutputString;
if (iMessageType == 1) { sTitle = sOutputString.match(/w+/); sBody = sOutputString.replace(/w+/, ''); var oBodyCellStyle = oBodyCell.style; if (oBodyCellStyle) { oBodyCell.style.backgroundColor = '#FCC'; } }
oMessageContainer.appendChild(oTitleRow); oTitleRow.appendChild(oTitleCell); oTitleCell.appendChild(oDocument.createTextNode(sTitle)); oMessageContainer.appendChild(oBodyRow); oBodyRow.appendChild(oBodyCell); oBodyCell.appendChild(oDocument.createTextNode(sBody)); oDebugWindow.focus(); } catch (vError) {
if (vError instanceof Error) { vError.handleError(); } } finally {
return vError ? null : true; } } </script> <!-- test.js --> <script type="text/javascript"> /** * +-------------------------------------------------------------------------+ * | jsPro - Test | * +-------------------------------------------------------------------------+ * | Copyright (C) 2001-2003 Stuart Wigley | * +-------------------------------------------------------------------------+ * | This library is free software; you can redistribute it and/or modify it | * | under the terms of the GNU Lesser General Public License as published by| * | the Free Software Foundation; either version 2.1 of the License, or (at | * | your option) any later version. | * | | * | This library is distributed in the hope that it will be useful, but | * | WITHOUT ANY WARRANTY; without even the implied warranty of | * | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser | * | General Public License for more details. | * | | * | You should have received a copy of the GNU Lesser General Public License| * | along with this library; if not, write to the Free Software Foundation, | * | Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | * +-------------------------------------------------------------------------+ * | Authors: Stuart Wigley <stuartwigley@yahoo.co.uk> | * | Randolph Fielding <gator4life@cinci.rr.com> | * +-------------------------------------------------------------------------+ * $Id: test.js,v 1.6 2003/09/15 05:07:09 gator4life Exp $ */
/** * Creates an object that provides methods for testing all jsPro libraries. * * @author Stuart Wigley * @version 1.0, 07/24/03 * @interface <code>new Test()</code> */ function Test() { }
/** * Evaluates and returns the result of a jsPro method using assumptions about * the structure and ids of HTML elements in the jsPro HTML test files. * * @author Stuart Wigley * @author Randolph Fielding * @version 1.1, 08/20/03 * @interface <code>Test.evaluateMethod(oButton, sClass)</code> * @param oButton the HTML input-button element that is clicked * @param sClass the name of the jsPro class instance being tested * @return the result of attempting to evaluate a jsPro method * @return <code>null</code> if an exception is encountered * @throws IllegalArgumentException * @throws TypeMismatchException */ Test.prototype.evaluateMethod = function(oButton, sClass) {
try {
var vError = null; var iNumArguments = arguments.length;
if (iNumArguments != 2) { throw vError = new IllegalArgumentException('Error.evaluateMethod', 2, iNumArguments); }
if (typeof oButton != 'object') { throw vError = new TypeMismatchException('Error.evaluateMethod', 'object', typeof oButton); }
if (typeof sClass != 'string') { throw vError = new TypeMismatchException('Error.evaluateMethod', 'string', typeof sClass); }
var sMethodName = oButton.id; var oInput1 = document.getElementById(sMethodName + '1'); var oInput2 = document.getElementById(sMethodName + '2'); var oInput3 = document.getElementById(sMethodName + '3'); var oOutput = document.getElementById(sMethodName + 'Result'); var sArguments = '';
if (oInput1) { var sInput1Value = oInput1.value; if (sInput1Value != '') { var fInput1Value = parseFloat(sInput1Value); sArguments += (isNaN(fInput1Value)) ? ''' + sInput1Value + ''' : fInput1Value; } }
if (oInput2) { var sInput2Value = oInput2.value; if (sInput2Value != '') { var fInput2Value = parseFloat(sInput2Value); sArguments += (isNaN(fInput2Value)) ? ', '' + sInput2Value + ''' : ', ' + fInput2Value; } }
if (oInput3) { var sInput3Value = oInput3.value; if (sInput3Value != '') { var fInput3Value = parseFloat(sInput3Value); sArguments += (isNaN(fInput3Value)) ? ', '' + sInput3Value + ''' : ', ' + fInput3Value; } }
var vResult = eval(sClass + '.' + sMethodName + '(' + sArguments + ')'); } catch (vError) {
if (vError instanceof Error) { vError.handleError(); } } finally {
if (oOutput) { oOutput.value = vResult; } } } </script> <!-- validator.js --> <script type="text/javascript"> /** * +-------------------------------------------------------------------------+ * | jsPro - Validator | * +-------------------------------------------------------------------------+ * | Copyright (C) 2001-2003 Stuart Wigley | * +-------------------------------------------------------------------------+ * | This library is free software; you can redistribute it and/or modify it | * | under the terms of the GNU Lesser General Public License as published by| * | the Free Software Foundation; either version 2.1 of the License, or (at | * | your option) any later version. | * | | * | This library is distributed in the hope that it will be useful, but | * | WITHOUT ANY WARRANTY; without even the implied warranty of | * | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser | * | General Public License for more details. | * | | * | You should have received a copy of the GNU Lesser General Public License| * | along with this library; if not, write to the Free Software Foundation, | * | Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | * +-------------------------------------------------------------------------+ * | Authors: Stuart Wigley <stuartwigley@yahoo.co.uk> | * | Randolph Fielding <gator4life@cinci.rr.com> | * +-------------------------------------------------------------------------+ * $Id: validator.js,v 1.2 2003/09/22 03:17:34 gator4life Exp $ */
/** * Creates an object that provides methods for performing boolean validations. * * @author Stuart Wigley * @version 1.0, 09/19/03 * @interface <code>new Validator()</code> */ function Validator() { }
/** * Determine if the specified value is an empty string or a string composed of * only whitespace characters. * * @summary is blank string? * @author Stuart Wigley * @author Randolph Fielding * @version 1.1, 09/21/03 * @interface <code>Validator.isBlankString(vValue)</code> * @param vValue a value of any datatype * @return <code>true</code> if <code>vValue</code> is a string * and is either empty or composed of only whitespace * characters * @return <code>false</code> if <code>vValue</code> is either * not a string or is not an empty string and not a * string composed of only whitespace characters * @return <code>null</code> if an exception is encountered * @throws IllegalArgumentException */ Validator.prototype.isBlankString = function(vValue) {
try {
var vError = null; var iNumArguments = arguments.length;
if (iNumArguments != 1) { throw vError = new IllegalArgumentException('Validator.isBlankString', 1, iNumArguments); }
var bIsBlankString = (typeof vValue != 'string') ? false : (vValue.match(/S/g)) ? false : true; } catch (vError) {
if (vError instanceof Error) { vError.handleError(); } } finally {
return vError ? null : bIsBlankString; } }
/** * Determine if the specified value is a single digit. * * @summary is single digit? * @author Stuart Wigley * @author Randolph Fielding * @version 1.1, 09/21/03 * @interface <code>Validator.isDigit(vValue)</code> * @param vValue a value of any datatype * @return <code>true</code> if <code>vValue</code> is a number * and a single digit * @return <code>false</code> if <code>vValue</code> is either * not a number or is not a single digit * @return <code>null</code> if an exception is encountered * @throws IllegalArgumentException */ Validator.prototype.isDigit = function(vValue) {
try {
var vError = null; var iNumArguments = arguments.length;
if (iNumArguments != 1) { throw vError = new IllegalArgumentException('Validator.isDigit', 1, iNumArguments); }
var bIsDigit = (typeof vValue != 'number') ? false : ((vValue > 9) || (vValue.toString().length != 1)) ? false : true; } catch (vError) {
if (vError instanceof Error) { vError.handleError(); } } finally {
return vError ? null : bIsDigit; } }
/** * Determine if the specified value is an integer. * * @summary is integer? * @author Stuart Wigley * @author Randolph Fielding * @version 1.1, 09/21/03 * @interface <code>Validator.isInteger(vValue)</code> * @param vValue a value of any datatype * @return <code>true</code> if <code>vValue</code> is a number * and an integer * @return <code>false</code> if <code>vValue</code> is either * not a number or is not an integer * @return <code>null</code> if an exception is encountered * @throws IllegalArgumentException */ Validator.prototype.isInteger = function(vValue) {
try {
var vError = null; var iNumArguments = arguments.length;
if (iNumArguments != 1) { throw vError = new IllegalArgumentException('Validator.isInteger', 1, iNumArguments); }
var bIsInteger = (typeof vValue != 'number') ? false : (vValue.toString().indexOf('.') != -1) ? false : true; } catch (vError) {
if (vError instanceof Error) { vError.handleError(); } } finally {
return vError ? null : bIsInteger; } } </script> <script type="text/javascript"> var oTest = new Test(); var oDebug = new Debug(); var oValidator = new Validator(); </script> </head> <body> <table> <tbody> <tr> <td>Validator.isBlankString()</td> <td><input id="isBlankString1" name="input" type="text" size="5" /></td> <td><input id="isBlankString" type="button" value="Calculate >" onclick="oTest.evaluateMethod(this, 'oValidator')" /></td> <td><input id="isBlankStringResult" name="output" type="text" size="30" readonly="readonly" /></td> </tr> <tr> <td>Validator.isDigit()</td> <td><input id="isDigit1" name="input" type="text" size="5" /></td> <td><input id="isDigit" type="button" value="Calculate >" onclick="oTest.evaluateMethod(this, 'oValidator')" /></td> <td><input id="isDigitResult" name="output" type="text" size="30" readonly="readonly" /></td> </tr> <tr> <td>Validator.isInteger()</td> <td><input id="isInteger1" name="input" type="text" size="5" /></td> <td><input id="isInteger" type="button" value="Calculate >" onclick="oTest.evaluateMethod(this, 'oValidator')" /></td> <td><input id="isIntegerResult" name="output" type="text" size="30" readonly="readonly" /></td> </tr> </tbody> </table> </body> </html>
|