sessionemanager.htc

11917 단어 cssHTCperformance

<!-- ---------------------------------------------------------------------
//
//  Copyright 2001 Chordiant Software.  All Rights Reserved.
//
//  File:         sessionemanager.htc
//
//	Auther:				Ryan Carroll
//	Created:			13/11/2001
//
//  Description:  Implements a manager for user session settings.
//
//	Changes log:
//-------------------------------------------------------------------- -->

<PUBLIC:COMPONENT tagname="sessionmanager" lightWeight="true">

<!-- Public Properties -->    

<!-- Public Methods -->    
<METHOD   NAME="setSessionSetting"				/>
<METHOD   NAME="getSessionSetting"				/>
<METHOD   NAME="removeSessionSetting"				/>
<METHOD   NAME="clearSessionSettings"			/>
<METHOD   NAME="getAllSessionSettings"			/>


<!-- Public Events -->    
<EVENT    NAME="onError"  						ID="error"		  />
<EVENT    NAME="onSessionSettingChanged" 			ID="sessionSettingChanged" />

    
<!-- Private Event Listeners -->
<ATTACH   EVENT="ondocumentready" HANDLER="setDefaults" />
// { start - performance fix
<ATTACH   EVENT="ondetach"          HANDLER="cleanUp"       />
// } end - performance fix

</PUBLIC:COMPONENT>

<SCRIPT LANGUAGE="jscript">

//+----------------------------------------------------------------------------
//
//  Global Variables
//
//-----------------------------------------------------------------------------
var sessionSettings = new Array();

// { start - performance fix
// Detach event handlers. This should always be done for event handlers that was attached with the attachEvent method.
function cleanUp() {
  if (window)
    window.detachEvent("onbeforeunload", cleanUp);
	sessionSettings = null;
}
// } end - performance fix

function sessionSettingObject(sSessionSettingName, sSessionSettingValue)
{
	this.sessionSettingName = sSessionSettingName;
	this.sessionSettingValue = sSessionSettingValue;
}

////////////////////////////////////////////////////////////////////////////////
//	Methods Section																										        // 
////////////////////////////////////////////////////////////////////////////////

//+----------------------------------------------------------------------------
//
//  Public Methods
//
//-----------------------------------------------------------------------------


//+----------------------------------------------------------------------------
//
//  Function:       setSessionSetting
//
//  Description:    
//
//  Arguments:      none
//
//  Returns:        nothing
//
//-----------------------------------------------------------------------------

function setSessionSetting( sSessionSettingName, sSessionSettingValue ) {
	var oSessionSetting;
	var oEvent;

	try {
    	for(var i=0; i < sessionSettings.length; i++){
    		if(sessionSettings[i].sessionSettingName == sSessionSettingName){
    			oSessionSetting = sessionSettings[i];
    			oSessionSetting.sessionSettingValue = sSessionSettingValue;
    			break;
    		}
    	}
    	
    	if(oSessionSetting == null){
    		oSessionSetting = new sessionSettingObject(sSessionSettingName, sSessionSettingValue);
    		sessionSettings[sessionSettings.length] = oSessionSetting;
    	} 
    
    	oEvent = createEventObject();
        oEvent.setAttribute("sessionSettingData", oSessionSetting);
        sessionSettingChanged.fire(oEvent);
	} catch(e) {
	  	returnError(e.toString());
	} finally {
		oSessionSetting = null;
		oEvent = null;
		sSessionSettingName = null;
		sSessionSettingValue = null;
	}	
}


//+----------------------------------------------------------------------------
//
//  Function:       getSessionSetting
//
//  Description:    
//
//  Arguments:      none
//
//  Returns:        nothing
//
//-----------------------------------------------------------------------------

function getSessionSetting( sSessionSettingName ) {
	try {
    	for(var i=0; i < sessionSettings.length; i++){
    		if(sessionSettings[i].sessionSettingName == sSessionSettingName){
    			return sessionSettings[i].sessionSettingValue;
    		}
    	}
    	
    	return null;
	} catch(e) {
	  	returnError(e.toString());
		return null;
	} finally {
		sSessionSettingName = null;
	}	
}


//+----------------------------------------------------------------------------
//
//  Function:       removeSessionSetting
//
//  Description:    
//
//  Arguments:      none
//
//  Returns:        nothing
//
//-----------------------------------------------------------------------------

function removeSessionSetting(sSessionSettingName) {
	var oRemovedSessionSetting;

	try {
    	for(var i=0; i < sessionSettings.length; i++){
    		if(sessionSettings[i].sessionSettingName == sSessionSettingName){
    			oRemovedSessionSetting = sessionSettings.splice(i,1);
    			return oRemovedSessionSetting;
    		}
    	}
    	
    	return null;
	} catch(e) {
	  	returnError(e.toString());
		return null;
	} finally {
	  	oRemovedSessionSetting = null;
		sSessionSettingName = null;
	}	
}



//+----------------------------------------------------------------------------
//
//  Function:       clearSessionSettings
//
//  Description:    
//
//  Arguments:      none
//
//  Returns:        nothing
//
//-----------------------------------------------------------------------------

function clearSessionSettings() {
	var oRemovedSessionSettings;

	try {
		oRemovedSessionSettings = sessionSettings.splice(0,sessionSettings.length);
	} catch(e) {
	  	returnError(e.toString());
	} finally {
	  	oRemovedSessionSettings = null;
	}	
}



//+----------------------------------------------------------------------------
//
//  Function:       getAllSessionSettings
//  Description:    
//
//  Arguments:      none
//
//  Returns:        nothing
//
//-----------------------------------------------------------------------------

function getAllSessionSettings() {
	var oAllSessionSettings;
	
	try {	
    	oAllSessionSettings = new Array;
    	for(var i=0; i < sessionSettings.length; i++){
    		oAllSessionSettings[oAllSessionSettings.length] = sessionSettings[i]; 
    	}
    	
    	return oAllSessionSettings;
	} catch(e) {
	  	returnError(e.toString());
		return null;
	} finally {
	  	oAllSessionSettings = null;
	}	
}


//+----------------------------------------------------------------------------
//
//  Private Methods
//
//-----------------------------------------------------------------------------


//+----------------------------------------------------------------------------
//
//  Function:       setDefaults
//
//  Description:    Called during the initialization of the behavior.  Sets
//                  the required default settings, and attaches the 
//                  onpropertychange event (not done in the header to prevent 
//                  firing the event during initialization).
//
//  Arguments:      none
//
//  Returns:        nothing
//
//-----------------------------------------------------------------------------

function setDefaults()
{ 
	if(element.document.media != "print") {
		//  Attach the onpropertychange event
		attachEvent("onpropertychange", doPropChange);
	}
// { start - performance fix
  window.attachEvent("onbeforeunload", cleanUp);				
// } end - performance fix
}


//+----------------------------------------------------------------------------
//
//  Function:       doPropChange
//
//  Description:    Runs on the onpropertychange event and calls the necessary
//                  functions to correctly handle the property that was just
//                  changed.
//
//  Arguments:      none
//
//  Returns:        nothing
//
//-----------------------------------------------------------------------------

function doPropChange()
{
 	var propertyName;
	
 	try {
         propertyName = window.event.propertyName;
     
         //  Handle CSS property changes by calling necessary functions, setting
         //  variables, and/or setting styles
         //
         if (propertyName.substring(0,5) == "style")
         {
     	   // Handle Style changes
            // switch(propertyName)
            // {
            //     case "style.zIndex"             :
            //         break;                
            // }
         }
         else
         {
             //
             //  Detach the onpropertychange event to prevent it from firing while
             //  the changes are handled
             //
             detachEvent("onpropertychange", doPropChange);
             
             // Handle Property changes
             switch(propertyName)
             {
                 //case "leftBoundary" :
                 //		leftBoundary = parseInt(leftBoundary);
                 //		setLeftBoundary(leftBoundary);
                 //    break;
                   						    
                 default :
                     returnError(propertyName + " not a valid property");
                     break;
             }
             
             //  Re-attach the onpropertychange event
             attachEvent("onpropertychange", doPropChange);
         }
	} catch(e) {
	  	returnError(e.toString());
	} finally {
	  	propertyName = null;
	}	
}


//+----------------------------------------------------------------------------
//
//  Function:       returnError
//
//  Description:    Fires the error event, along with a descriptive text
//                  message.
//
//  Arguments:      sMsg - descriptive text message
//
//  Returns:        nothing
//
//-----------------------------------------------------------------------------

function returnError(sMsg)
{
	var oEvent;
 	try {
        oEvent = createEventObject();
        oEvent.setAttribute("error", sMsg);
        error.fire(oEvent);
    	//alert(sMsg);
	} finally {
	  	oEvent = null;
		sMsg = null;
	}
}


</SCRIPT>


좋은 웹페이지 즐겨찾기