@script name="Caches">
   Cache operations that helps the developer debugging the server caches
   (c) SAP AG 2003-2006. All rights reserved.
var _progressHandle = null;
var _interval = null;
var _counter = 0;
function handleCacheAction(action) {
	switch(action) {
		case 1:
		case 2:
		case 3:
		case 4:
		case 5:
			clear(action);
			break;
	    case 7:
			$WIN.closeAllWindows(true);
			break;
		case 10:
			writeToFS(action);
			break;
		case 15:
			help();
			break;
	}
}
function clear(action){
	var res = false;
	switch(action) {
		//server cache
		case 1:
			res = $ENV.channel1.executeService('DataAccessObject',"clearCache", null, null, null);
			break;
		//persisted server cache (in file system)
		case 2:
			$ENV.channel1.executeService('DataAccessObject',"clearFromFS", null, null, null);
			break;
		//kit manifest
		case 3:
			$ENV.channel1.executeService('LibManager',"clearKitsManifest", null, null, null);
			break;
		//unit cache
		case 4:
			$ENV.channel1.executeService('Reader',"clearUnitsCache", null, null, null);
			break;
			//client cache
		case 5:
			//$ENV.channel1.executeService('Reader',"clearUnitsCache", null, null, null);
			PROMPT("Not implemented");
			return;
	}
	result(res, "Cache is cleared");
}
//save the server cache to J2EE's DB
function writeToFS(action){
	var res = false;
	switch(action) {
		//server cache
		case 10:
			_progressHandle = PROGRESS_START("Saving...");
			_interval = setInterval(progress, 1000);
			res = $ENV.channel1.executeServiceAsync('DataAccessObject',"writeToFS", null, onEndExecute, onEndExecute, null);
			return;
		//unit cache - not implemented
		//case 11:
	}
	result(res, "Server cache saved to File System");
}
function progress() {
	if(_counter >= 100)
		_counter=0;
	_counter += 5;
	PROGRESS_UPDATE(_progressHandle, "Saving...", _counter);
}
function onEndExecute(response) {
	if(_progressHandle)
		PROGRESS_FINISH(_progressHandle, "Server cache saved");
	clearInterval(_interval);
	_progressHandle = null;
	_interval = null;
 	result(response, "Server cache saved to File System");
}
function result(res, msg) {
	if(res.nodeName == "ERROR")
		PROMPT("Error has occured
"+res.getAttribute("error"));
	else
		PROMPT(msg);
	if(res.nodeName != "SUCCESS" && res.text)
		WRITE(res.text)
}
function help(){
	var msg = "Server Cache - contains all parsed files (gs, htm, htc, js, xml-rules, etc.). It is a memory cache in the J2EE engine.
";
	msg += "Client Cache - VC files are kept in browser cache (htm, htc, js, gs and rules are kept in one XML file)
";
	msg += "Kits Manifest - contains a list of all VC packages and kits deployed on the system (Cached in LibManager)
";
	msg += "Clear Server Cache - clears the cache of all files in the server
";
	msg += "Save Server Cache - save the files kept in the server to the file system. Can be browsed in NWA - Java Configuration Browser->developmentServer->ServerCache
";
	msg += "Clear Persisted Server Cache - delete the files that were saved using 'save server cache' option from file system";
	PROMPT(msg);
}
	/*
		Clear Server Cache
		Server Cache contains all parsed files (gs, htm, htc, js, xml-rules, etc.)
		Clear Persisted Server Cache
		Delete the persisted cache in file system
		Clear Kits Manifest
		Kits Manifest contains a list of all VC packages and kits deployed on the system
		Clear Units Cache
		Save Server Cache
	*/