TROIKA.ASP - the MVC framework

Dispatcher.js

Summary

Contains Dispatcher 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
Dispatcher This is Dispatcher class which processes the ResponseContext deciding what to do with it.

/**
* @fileoverview Contains <tt>Dispatcher</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 Dispatcher class.
*
* @class This is <tt>Dispatcher</tt> class which processes the <tt>ResponseContext</tt> deciding what to do with it.
* It either delegate to <tt>XSLEngine</tt> to render the view or redirects browser to different URI.
*
* @constructor
* @param {Environment} environment The instance of <tt>Environment</tt> class.
*/
function Dispatcher(environment) {

    /**
    * Performs business logic here.
    *
    * @param {RequestContext} requestCtx The instance of <tt>RequestContext</tt> class.
    * @param {ResponseContext} responseCtx The instance of <tt>ResponseContext</tt> class.
    */
    this.execute = function (requestCtx, responseCtx) {

        var forward = responseCtx.forward;
        var path = forward.path;
        var response = environment.response;

        if (forward.redirect) {

            response.redirect(path);
        }
        else {

            var data =  new HashMap();
            var app = environment.application;

            data.put("requestCtx", requestCtx);
            data.put("responseCtx", responseCtx);

            environment.reset();//refresh session vars
            var sessionData = environment.session.getSessionData();
            if (sessionData) {

                data.put("sessionData", sessionData);
            }

            renderView(environment, path, data.toXML());
        }
    };

    function renderView(environment, path, xml) {

        var app = environment.application;
        var response = environment.response;

        var xslEngine =  new XSLEngine(app.getAppRoot() + "/WEB-INF" + path);

        response.write(xslEngine.transform(xml));

        if (app.get("debug") == "1") {

            response.write("<!" + "--" + xml + "-->");
        }
    }
}

TROIKA.ASP - the MVC framework

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