<HTML>
<HEAD>
<!-- Copyright 2001, 2002, 2003 Macromedia, Inc. All rights reserved. -->

<SCRIPT LANGUAGE="javascript">


//--------------------------------------------------------------------
// FUNCTION:
//   getServerModelDisplayName
//
// DESCRIPTION:
//   Returns the name that should be displayed in the UI for
//   this Server Model
//
//   This value can be accessed from JavaScript by calling the
//   function:
//     dom.serverModel.getDisplayName()
//
// ARGUMENTS:
//   None
//
// RETURNS:
//   string
//--------------------------------------------------------------------

function getServerModelDisplayName()
{
  return "JSP";
}


//--------------------------------------------------------------------
// FUNCTION:
//   getServerModelFolderName
//
// DESCRIPTION:
//   Returns the folder name that will be used for this Server Model
//   within the Configuration folder
//
//   This value can be accessed from JavaScript by calling the
//   function:
//     dom.serverModel.getFolderName()
//
// ARGUMENTS:
//   None
//
// RETURNS:
//   string
//--------------------------------------------------------------------

function getServerModelFolderName()
{
  return "JSP";
}


//--------------------------------------------------------------------
// FUNCTION:
//   getServerInfo
//
// DESCRIPTION:
//   Returns a JavaScript Object, which can be accessed from within
//   the JavaScript code.
//
//   The entire object can be retreived through the JavaScript function:
//     dom.serverModel.getServerInfo();
//
//   The properties: serverName, serverLanguage, and serverVersion
//   are special properties, which can also be accessed with the
//   JavaScript functions:
//     dom.serverModel.getServerName()
//     dom.serverModel.getServerLanguage()
//     dom.serverModel.getServerVersion();
//
// ARGUMENTS:
//   None
//
// RETURNS:
//   Object
//--------------------------------------------------------------------

function getServerInfo()
{
  var obj = new Object();

  obj.serverName = "JSP";
  obj.serverLanguage = "Java";
  obj.serverVersion = "1.0"

  obj.recordsetDisplayName = MM.LABEL_TitleRecordset;
  obj.recordsetBaseName = MM.LABEL_RecordsetBaseName;
  obj.defaultRadioButtonSB = MM.LABEL_DynamicRadioSBFileTitle;
  obj.defaultCheckboxSB = MM.LABEL_DynCheckboxSBFileTitleJSP;
  obj.defaultListboxSB = MM.LABEL_DynamicListMenuSBFileTitle;

  return obj;
}


//--------------------------------------------------------------------
// FUNCTION:
//   getServerModelExtDataNameUD4
//
// DESCRIPTION:
//   Returns the Server Model Implementation name that should be used
//   when accessing UD4 extension data files that live in the folder:
//     Configurations/ExtensionData
//
// ARGUMENTS:
//   None
//
// RETURNS:
//   string
//--------------------------------------------------------------------

function getServerModelExtDataNameUD4()
{
  return "JSP";
}


//--------------------------------------------------------------------
// FUNCTION:
//   getFileExtensions
//
// DESCRIPTION:
//   Returns a JavaScript Array of the file extensions which will
//   be listed as potential default file extensions on the Application
//   Server configuration page within the Site definition dialog.
//
// ARGUMENTS:
//   None
//
// RETURNS:
//   Array
//--------------------------------------------------------------------

function getFileExtensions()
{
  FileExtensionArray = new Array();

  FileExtensionArray[0] = ".jsp";
  FileExtensionArray[1] = ".htm";
  FileExtensionArray[2] = ".html";
  FileExtensionArray[3] = ".java";

  return FileExtensionArray;
}


//--------------------------------------------------------------------
// FUNCTION:
//   getVersionArray
//
// DESCRIPTION:
//   Returns a JavaScript Array of JavaScript Objects.  Each object
//   contains a Name and a Version propery.
//
//   The version values can be accessed from JavaScript by calling the
//   function:
//     dom.serverModel.getServerVersion(name)
//
// ARGUMENTS:
//   None
//
// RETURNS:
//   Array
//--------------------------------------------------------------------

function getVersionArray()
{
  VersionArray = new Array();

  VersionObject = new Object();
  VersionObject["Name"]="JSP";
  VersionObject["Version"]="1.0";
  VersionArray[0]=VersionObject;

  VersionObject = new Object();
  VersionObject["Name"]="JDBC";
  VersionObject["Version"]="1.0";
  VersionArray[1]=VersionObject;

  VersionObject = new Object();
  VersionObject["Name"]="supportsErrorPage";
  VersionObject["Version"]="";
  VersionArray[2]=VersionObject;

  return VersionArray;
}


//--------------------------------------------------------------------
// FUNCTION:
//   getServerSupportsCharset
//
// DESCRIPTION:
//   Returns true if the current server supports the given charset
//
//   The CharSet support be accessed from JavaScript by calling the
//   function:
//     dom.serverModel.getServerSupportsCharset(metaCharSetString)
//
// ARGUMENTS:
//   metaCharSetString - string - the value of the documents "charset="
//
// RETURNS:
//   Array
//--------------------------------------------------------------------

function getServerSupportsCharSet( metaCharSetString )
{
  //JSP Supports all character sets
  return true;
}

//--------------------------------------------------------------------
// FUNCTION:
//   updatePageDirective
//
// DESCRIPTION:
//   This function is called when a user changes their document encoding
//	 or the document type of their document.
//
// ARGUMENTS:
//   dom - The Document DOM of the document to be opened.
//
// RETURNS:
//   none
//--------------------------------------------------------------------

function updatePageDirective(dom)
{
  if (dom)
  {
    encoding = dom.getCharSet();
    if (encoding)
    {
      var docStr = dom.documentElement.outerHTML;
      var pageDirectiveStart = docStr.search( /<%@\s*Page/i );
	  var updateDoc = false;

      if( pageDirectiveStart > -1 )
      {
        var pageDirectiveEnd = 0;
        pageDirectiveEnd = docStr.indexOf("%>", pageDirectiveStart) + 2;

        if(pageDirectiveEnd > 1 && pageDirectiveEnd > pageDirectiveStart)
        {
          var oldLangStr = docStr.substring(pageDirectiveStart, pageDirectiveEnd);
          var newLangStr = oldLangStr.replace(/(charset=)[\w-]*/i, "$1" + encoding);
          if (newLangStr != oldLangStr)
          {
            var newDocStr = docStr.substring(0, pageDirectiveStart) +
                            newLangStr +
                            docStr.substring(pageDirectiveEnd);
			docStr = newDocStr;
			updateDoc = true;
          }
        }
      }
	  
	  var requestEncodingStart = docStr.search( /request.setCharacterEncoding\(["'][\w-]*["']\)/i );
	  
	  if( requestEncodingStart > -1 )
	  {
	  	var requestEncodingEnd = 0;
		requestEncodingEnd = docStr.indexOf( ")", requestEncodingStart) + 1;
		
		if( requestEncodingEnd > 1 && requestEncodingEnd > requestEncodingStart )
		{
		  var oldLangStr = docStr.substring(requestEncodingStart, requestEncodingEnd);
		  var newLangStr = oldLangStr;
		  newLangStr = newLangStr.replace(/(request.setCharacterEncoding\()"[\w-]*"\)/i, "$1\"" + encoding + "\")"); // double quotes
          newLangStr = newLangStr.replace(/(request.setCharacterEncoding\()'[\w-]*'\)/i, "$1'" + encoding + "')");   // single quotes
          if (newLangStr != oldLangStr)
          {
            var newDocStr = docStr.substring(0, requestEncodingStart) +
                            newLangStr +
                            docStr.substring(requestEncodingEnd);
			docStr = newDocStr;
			updateDoc = true;
          }
		}
	  }
	  
	  if( updateDoc )
	  {
	  	dom.documentElement.outerHTML = docStr;
	  }
    }
  }
}


//--------------------------------------------------------------------
// FUNCTION:
//   getServerModelDelimiters
//
// DESCRIPTION:
//   Returns the script delimiters which are used by the application
//   server, and states whether each can or cannot participate in
//   merging of code blocks.
//
//   This value can be accessed from JavaScript by calling the
//   function:
//     dom.serverModel.getDelimiters()
//
// ARGUMENTS:
//   None
//
// RETURNS:
//   Array
//--------------------------------------------------------------------

function getServerModelDelimiters()
{
	DelimArray = new Array();

	DelimObject = new Object();
	DelimObject["startPattern"]="<%";
	DelimObject["endPattern"]="%>";
	DelimObject["participateInMerge"]=true;
	DelimArray[0]=DelimObject;

	DelimObject = new Object();
	DelimObject["startPattern"]="<%\\s*=";
	DelimObject["endPattern"]="%>";
	DelimObject["participateInMerge"]=false;
	DelimArray[1]=DelimObject;

	DelimObject = new Object();
  // Note the extra (?!@) in pattern below. This means do not match <%@ if it is
  //   followed by another @. Also, the character matched by (?!@) is not extracted
  //   in the regexp. This case is needed in case we see a participant like:
  //   "<% @@param1@@ ...". We still want to strip the <% in this case.
	DelimObject["startPattern"]="<%\\s*@(?!@)";
	DelimObject["endPattern"]="%>";
	DelimObject["participateInMerge"]=false;
	DelimArray[2]=DelimObject;

	DelimObject = new Object();
	DelimObject["startPattern"]="<%\\s*\\!";
	DelimObject["endPattern"]="%>";
	DelimObject["participateInMerge"]=false;
	DelimArray[3]=DelimObject;

	return DelimArray;
}



//--------------------------------------------------------------------
// FUNCTION:
//   getLanguageSignatures
//
// DESCRIPTION:
//   Returns the method and array signatures used by the scripting
//   language.
//
// ARGUMENTS:
//   None
//
// RETURNS:
//   Array
//--------------------------------------------------------------------

function getLanguageSignatures()
{
	Signatures = new Object();

	// method signature
	Signatures["Method"] = "$$RETURNTYPE $$METHODNAME($$ARGUMENT, $$ARGUMENT) $$THROWS $$EXCEPTION, $$EXCEPTION";

	// constructor signature
	Signatures["Constructor"] = "$$METHODNAME($$ARGUMENT, $$ARGUMENT) $$THROWS $$EXCEPTION, $$EXCEPTION";

	// dropcode signatures
	Signatures["Dropcode"] = "$$RETURNTYPE a$$RETURNVALUE = $$OBJECTNAME.$$METHODNAME($$ARGUMENT, $$ARGUMENT);"
	Signatures["ConstructorDropcode"] = "$$METHODNAME a$$RETURNVALUE = new $$METHODNAME($$ARGUMENT, $$ARGUMENT);"
	Signatures["VoidDropcode"] = "$$OBJECTNAME.$$METHODNAME($$ARGUMENT, $$ARGUMENT);"

	// array signature
	Signatures["Array"] = "$$ARRAYNAME[]";
	Signatures["ArrayBracket"] = "[]";

	// reference signature
	Signatures["Reference"] = "";

	//throws signature
	Signatures["Throws"] = "throws";

	// try signature
	Signatures["Try"] = "try{";
	Signatures["EndTry"] = "}";

	// catch signature
	Signatures["Catch"] = "catch($$EXCEPTION e){";
	Signatures["EndCatch"] = "}";

	Signatures["BeginBlockComment"] = "/*";
	Signatures["EndBlockComment"] = "*/";

	// data type mappings
	PrimitiveTypes = new Object();
	Signatures["PrimitiveTypes"] = PrimitiveTypes;
	PrimitiveTypes["VOID"] = "void";
	PrimitiveTypes["BOOLEAN"] = "boolean";
	PrimitiveTypes["I1"] = "byte";	// 8-bit signed integer
	PrimitiveTypes["U1"] = "byte";	// 8-bit unsigned integer
	PrimitiveTypes["I2"] = "short";	// 16-bit signed integer
	PrimitiveTypes["U2"] = "short";	// 16-bit unsigned integer
	PrimitiveTypes["CHAR"] = "char";	// character
	PrimitiveTypes["I4"] = "int";	// 32-bit signed integer
	PrimitiveTypes["U4"] = "int";	// 32-bit unsigned integer
	PrimitiveTypes["I8"] = "long";	// 64-bit signed integer
	PrimitiveTypes["U8"] = "long";	// 64-bit unsigned integer
	PrimitiveTypes["R4"] = "float";	// 32-bit floating point
	PrimitiveTypes["R8"] = "double";	// 64-bit floating point

	return Signatures;
}


//--------------------------------------------------------------------
// FUNCTION:
//   inspectDynamicDataRef
//
// DESCRIPTION:
//
// ARGUMENTS:
//
// RETURNS:
//--------------------------------------------------------------------

function inspectDynamicDataRef(expression)
{
  var retArray = new Array();
  if(expression.length)
  {
    var TranslatorDOM = dreamweaver.getDocumentDOM(dreamweaver.getConfigurationPath() + "/Translators/JSP.htm");
    if (TranslatorDOM)
    {
      TranslatedStr = TranslatorDOM.parentWindow.translateMarkup("", "", expression);
      if (TranslatedStr.length)
      {
        document.documentElement.outerHTML = TranslatedStr;
        var dynamicContentNodes = document.documentElement.getElementsByTagName("MM_DYNAMIC_CONTENT");
        if (dynamicContentNodes.length == 1)
        {
          retArray[0] = dynamicContentNodes[0].getAttribute("SOURCE");
          retArray[1] = dynamicContentNodes[0].getAttribute("BINDING");
        }
      }
      document.documentElement.outerHTML = "<html></html>";
    }
  }
  return retArray;
}


//--------------------------------------------------------------------
// FUNCTION:
//   canRecognizeDocument
//
// DESCRIPTION:
//   This function is called when a user attempts to open a document
//   whose file extension matches two or more Document Types.
//
// ARGUMENTS:
//   dom - The Document DOM of the document to be opened.
//
// RETURNS:
//   integer +ve integer if document is identified.
//           -ve integer if not.
//--------------------------------------------------------------------
function canRecognizeDocument(dom)
{
  return 1;
}

</SCRIPT>
</HEAD>
<BODY>
</BODY>
</HTML>
