Home
Categories
Dictionary
Download
Project Details
Changes Log
FAQ
License

Scripts MIME types





The following script languages are supported: Several MIME types are supported for each scripting language. The MIME is defined through the type attribute of the script element. For example:
   <script type="application/groovy">
   public int getValue(){
     return 10;
   }
   </script>

Languages MIME types

Javascript MIME types

The MIME types supported for Javascript scripts are:
  • "text/javascript"
  • "text/ecmascript"
  • "application/javascript"
  • "application/ecmascript"
  • "application/x-javascript"

Groovy MIME types

The MIME types supported for Groovy scripts are:
  • "text/groovy"
  • "application/javascript"
  • "application/groovy"
  • "application/x-groovy"

Python MIME types

The MIME types supported for Python scripts are:
  • "text/python"
  • "application/python"
  • "application/x-python"

Ruby MIME types

The MIME types supported for Ruby scripts are:
  • "text/rb"
  • "text/ruby"
  • "application/ruby"
  • "application/x-ruby"

Inferring script types

The algorithm to infer the language of a script is the following:
  • If the script element has a type attribute, the framework will use this MIME type to get the language of the script
  • If the script element has no type attribute but it is an external script, the framework will use the extension of the script file to infer the language of a script
  • If the script is external but the file has no extension, or embedded without a type attribute, the framework will assume that it is a Javascript script
For example:
  • This script is detected as a Groovy script because of the type attribute:
      <script type="text/groovy"> 
       public int clicked() {
         context.echo("Clicked!");
       }
      </script>
    
  • This script is assumed by default to be a Javascript script:
      <script> 
       function clicked() {
         print("Clicked!");
       }
      </script>
    
  • This script is detected as a Groovy script because of the file extension:
      <script src="myScript.groovy" />
    

Understanding Script parsing exceptions

You can have strange exceptions when parsing you script if you defined the wrong MIME type. For example if you have the following embedded script:
   <script>
   public int checked() {
     context.echo("checked!");
   }      
   </script>
The framework will show the following exception:
scripterrormime
The reason here is that:
  • You did not define a MIME type for your script
  • As this is an embedded script, the framework assumed it was a Javascript script
  • Obviously it is a Groovy script, so the framework tried to compile the script as Javascript but failed

See also


Categories: scripts

Copyright 2008-2020 Herve Girod. All Rights Reserved. Documentation and source under the LGPL licence