TROIKA.ASP - the MVC framework

Utils.js

Summary

Contains Utils class.

This is part of Troika.ASP Framework - web development MVC framework for ASP 3.0. Please visit www.troika-asp.com for more details.



Version: $Revision: 1.3 $

Author: Pavel Chuchev pav@troika-asp.com


Class Summary
Utils This is generatl utility class.

/**
* @fileoverview Contains <tt>Utils</tt> class.
*
* <p>
* This is part of Troika.ASP Framework - web development MVC framework for ASP 3.0.
* Please visit {@link http://www.troika-asp.com www.troika-asp.com} for more details.
* </p>
*
* @author Pavel Chuchev pav@troika-asp.com
* @version $Revision: 1.3 $
*/
/**
* Constructs a new instance of <tt>Utils</tt> class.
*
* @class This is generatl utility class.
*
* @constructor
*/
function Utils() {

}
/**
* Reads file by name
*
* @param {String} fileName The file name to read.
* @return The file contents as a string
* @type String
*/
Utils.readFile = function (fileName) {

    if (!fileName) {

        throw new Error("Utils.readFile() IllegalArgumentException: 'fileName' undefined");
    }

    fileName = "" + fileName;
    var forReading = 1;

    var fso =  new ActiveXObject("Scripting.FileSystemObject");
    var f = fso.OpenTextFile(fileName, forReading);

    var result = f.ReadAll();

    f.close();

    return result;
};
/**
* Writes a string to a file.
*
* @param {String} file The file name to write.
* @param {String} text The text to write.
*/
Utils.writeFile = function (file, text) {

    if (!file) {

        throw new Error("Utils.writeFile() IllegalArgumentException: 'file' undefined");
    }

    file = "" + file;
    var fso =  new ActiveXObject("Scripting.FileSystemObject");
    var f = fso.CreateTextFile(file, true);

    f.writeLine(text);

    f.close();
};
/**
* Generates a random string.
*
* @param {String} passLength Sets the lenth of the random string.
* @return Returns a random string.
*
*/
Utils.getRandString = function (passLength) {

    var keylist = "abcdefghijklmnopqrstuvwxyz123456789";

    result = "";
    for (i = 0; i < passLength; i++) {

        result += keylist.charAt(Math.floor(Math.random() * keylist.length));
    }

    return result;
};

TROIKA.ASP - the MVC framework

www.troika-asp.com
Documentation generated on Sun Jun 15 17:59:32 2008