Table of ContentsPreviousNext

Put your logo here!


3 Developing Maplet Applications for MapleNet

In this Chapter

3.1 Writing a Maplet Application Compliant with MapleNet

When writing a Maplet application for MapleNet, follow these guidelines.

Restrictions

When using Maplet applications in MapleNet, consider the following restrictions.

3.2 Creating an HTML Page

Before you can publish to the MapleNet server, you must create an HTML page that references the saved .maplet file.

The following sample code (Listing 5) illustrates how to build a page for Internet Explorer and Mozilla browsers.

Note: Java applets that require a Java version greater than 1.1 must use the Java Plugin. Use the <object> tag in Internet Explorer and the <embed> tag in Mozilla browsers (e.g., Firefox). For a complete discussion of setting up web pages for simultaneous Internet Explorer and Firefox support, refer to http://download.oracle.com/javase/1.5.0/docs/guide/plugin/developer_guide/using_tags.html.
Listing 5 Maplet Application HTML Code

<html>

  <head>

    <title>Maplet Application Test Page</title>

  </head>



  <body>

    This web page contains an applet that will call the Maplet application specified below. The Maplet application will appear in a separate window. <br>

    <center>

      <object classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"

              width="400"

	          height="300"

	          align="middle" >

	    <param name="CODEBASE" value = "." />

	    <param name="CODE" value = "com.maplesoft.maplenet.maplets.MapletLoader.class"/>

	    <param name="ARCHIVE" value = "/maplenet/jar/mapletloader.jar, /maplenet/jar/mnc-index.jar" />

	    <param name="NAME" value = "plot_02_x" />

	    <param name="mapleFile" value="mytest.maplet" />

	    <param name="user" value="client" />

	    <param name="password" value="demopass" />

	    <param name="scriptable" value="true" />

	    <param name="mayscript" value="true" />

	    <param name="debug" value="false" />

	    <param name="callback" value="mapletDone" />

	    <param name="initCommands" value="x:=1" />

	    <param name="initFunction" value="mapletInit" />

	    <comment>

	      <embed type="application/x-java-applet;version=1.6"

	             width="400"

	             height="300"

	             align="middle"

	             code="com.maplesoft.maplenet.maplets.MapletLoader.class"

	             codebase="./"

	             archive="/maplenet/jar/mapletloader.jar,/maplenet/jar/mnc-index.jar"

	             mapleFile="mytest.maplet"

	             scriptable="true"

	             mayscript="true"

	             debug="false"

	             callback="mapletDone"

	             initCommands="x:=1"

	             initFunction="mapletInit"

	             user="client"

	             password="demopass">

	             <noembed> </comment> Error Java 1.6 not supported </noembed>

	      </embed>

      </object>

    </center>

  </body>

</html>

Note: ensure that all mnc-*.jar files (see the complete list of JAR files in the Appendix) are in the same directory as the mnc-index.jar file.

If you choose to use an applet tag in your web site, the parameters must be specified as shown in Listing 6.

Listing 6 Applet Parameter Syntax


<applet width="400"

        height="300"

        align="middle"

        code=" com.maplesoft.maplenet.maplets.MapleLoader.class"

        codebase="./"

        archive=" /maplenet/jar/mapletloader.jar, /maplenet/jar/mnc-index.jar" >

  <param name=" mapleFile" value="mytest.maplet"/>

  <param name="user" value="client"/>

  <param name="password" value="demopass"/>

  <param name="scriptable" value="true" />

  <param name="mayscript" value="true" />

  <param name="debug" value="false" />

  <param name="callback" value="mapletDone" />

  <param name="initCommands" value="x:=1" />

  <param name="initFunction" value="mapletInit" />

</applet>

Note: prior to MapleNet, Release 2.0, Maplet applications were loaded via the class com.maplesoft.client.maplets.MapletLoader. This class is now deprecated and must be replaced by com.maplesoft.maplenet.maplets.MapletLoader.

Specifying Parameters

In the .html file, specify the parameters listed in Table 4.

Table 4 HTML File Parameters
Parameter
Description
height
Specifies the height of the Maplet application on the web page.
width
Specifies the width of the Maplet application on the web page.
codebase
Specifies the directory from which to load the class file.
code
Specifies the required class file. For Maplet applications, MapletLoader class is always called.
archive
Specifies JAR files that are required, for example, mapletloader.JAR and mnc-index.jar
Note: Ensure the path to JAR files is correct for your system.
mapleFile
Specifies the Maplet application file.
scriptable
If true, allows JavaScript in the web page to access public data and methods in the MapletLoader applet. If false, public data and methods in the MapletLoader applet are hidden. Default is false.
mayscript
If true, the MapleLoader applet can call JavaScript functions defined in the web page. If false, JavaScript is not accessible from the Applet. Default is false
debug
If true, the MapleLoader applet prints debugging information to the Java Console Window of the browser. If false, no debugging data is printed. Default is false.
callback
Define the name of a JavaScript function to invoke when the Maplet Shutdown command is invoked. It will be called with one argument, a string, containing the result of the Shutdown command. The default is no callback is defined.
initCommands
If set, this string contains a valid Maple expression that is passed to the Maple kernel prior to the loading of the Maplet. Default is that no expression is defined.
initFunction
If set, it defines the name of a JavaScript function to invoke prior to loading of the Maplet. The function is called with no arguments and is expected to return a string containing a valid Maple expression. This string is then appended to the expression, if any, from the initCommands parameter and then passed to the Maple kernel prior to the loading of the Maplet. Default is to call a JavaScript function "mapletInit". To disable, set this parameter to the empty string, "".

Loading the Web Page

When the browser loads a web page, it parses all of the html including any JavaScript code and then loads the MapletLoader applet. The MapleLoader code accesses the MapleNet server using classes contained in the Jar Files (listed in the Appendix), indexed by the mnc-index.jar file. These files must be accessible to the web browser.

To enable the use of either the initFunction or callback settings, both the scriptable and mayscript parameters must be set to true.

If there is an initFunction defined, e.g.

<param name="initFunction" value="mySettings" />

then the MapletLoader will invoke that JavaScript function using a technology called LiveConnect. If the web page contains a JavaScript of the form

<script type="text/javascript" language="JavaScript">
function mySettings() {
return "user:='tom';interest=4.5;principal:=10000;term:=5";
}
</script>

then the result of the MapletLoader calling mySetting() would return the string

"user:='tom';interest=4.5;principal:=10000;term:=5"

noting that you cannot embed double quotes in the returned string. Also, if initCommands was defined by

<param name="initCommands" value="compound:=false" />

then the MapletLoader would build a concatenated string similar to

"compound:=false;user:='tom';interest=4.5;principal:=10000;term:=5"

and evaluate it, using MapleNet, prior to loading and running the Maplet. In this manner, the Maplet can be given user-specific data. If neither initCommands nor initFunction are defined, the MapleLoader loads the Maplet immediately.

When the Maplet completes and invokes the Shutdown command that is part of the Maplet package, the Maplet loader takes the result of the Shutdown command, as a string, and invokes the defined callback. If the web page contains the parameter

<param name="callback" value="mapletDone" />

and also defines the JavaScript similar to

<script type="text/javascript" language="JavaScript">
function mapletDone( returnValue ){
msg = "Maplet return was = " + returnValue;
alert(msg);
}
</script>

then the JavaScript would be called as mapletDone("186.43"). The web page would display a dialog box (alert) with the message Maplet return was = 186.43.

When the Maplet application and the web page are created, publish them to the MapleNet server.

3.3 Publishing Maplets to the MapleNet Server

Publishing a Maplet to the MapleNet server requires copying the Maplet file and its associated HTML page to the appropriate directory on the server. The files can be copied to the server using any network file transfer tool, such as FTP, SSH, or WebDAV.

Consult your site administrator for specific details on where your files should be placed and what method should be used to transfer them.

Once the files are copied to the server, your content will be available by accessing the appropriate URL. For example, if your Maplet consists of the files

mymaplet.maplet

mymaplet.html

then assuming the MapleNet server is myserver.com and that your files were transferred to the maplets directory of the MapleNet web application, the Maplet can be accessed by pointing your browser to http://myserver.com/maplenet/maplets/mymaplet.html.

Consult your site administrator for the exact URL to access your content.


Table of ContentsPreviousNext