< Home < Documentation
Configurations
Here are some sample configurations for Apptoy. Using
java -cp ... net.sf.apptoy.RunApplication <configurationfile>.xml
loads the configuration and starts the Apptoy application.
On complete example
<?xml version="1.0" encoding="UTF-8"?>
<apptoy-config xmlns="http://apptoy.sf.net/config" >
<settings>
<log level="INFO"/>
</settings>
<sources>
<server
name="gui"
class="net.sf.apptoy.server.HTTPDocumentServer"
home="http://localhost:8080/Apptoy.Srv/swt" />
<server
name="resources"
class="net.sf.apptoy.server.ResourceServer"
home="net/sf/apptoy/resources"/>
<protocol name="http" class="net.sf.apptoy.server.HTTPDocumentServer" />
<protocol name="file" class="net.sf.apptoy.server.FileDocumentServer"/>
</sources>
<presenter class="net.sf.apptoy.ui.swt.SWTPresenter">
<renderer namespace="http://apptoy.sf.net/swt" class="net.sf.apptoy.ui.swt.SWTRenderer"/>
</presenter>
<script language="javascript">
<mainscript url="apptoy://gui/index.js"/>
<processor default="net.sf.apptoy.script.BSFProcessor"/>
</script>
</apptoy-config>
There are four main sections. The first is settings .
Global settings are done here (e.g. the log level).
The other sections are explained in more detail:
Document and Resource Sources (sources )
The second section sources defines how to translate URIs
used in Apptoy. A Server defines a name and a class which
handles URIs like apptoy://<name> . Additionally, a home
path must be provided where necessary.
Classes listed as Server must be derived from the abstract class net.sf.apptoy.server.DocumentServer .
At the moment there are the following classes implemented:
-
net.sf.apptoy.server.FileDocumentServer
This server uses the home directory and reads the
resources from the file system.
<server name="gui" class="net.sf.apptoy.server.FileDocumentServer" home="../Apptoy.Srv/WebContent/swt" />
Relative paths are relative to the working directory of the program.
This may help to create one configuration for multiple operating
systems.
-
net.sf.apptoy.server.HTTPDocumentServer
This server uses the home URI and reads the resources from
an HTTP server.
<server name="gui" class="net.sf.apptoy.server.HTTPDocumentServer" home="http://localhost:8080/Apptoy.Srv/swt" />
-
net.sf.apptoy.server.ResourceServer
This server uses the reads the resources from the classpath. That way,
resources may be packed into JAR files or into folders in the
classpath. home can be used to provide a home directory /
package name (separated with '/').
<server name="resources" class="net.sf.apptoy.server.ResourceServer" home="net/sf/apptoy/resources"/>
Presenter class definition (presenter )
The presenter is defined by a presenter class which
controls the rendering of a form and one or more renderer classes that
actually render the XML, each for a single namespace:
This is the very basic setup for SWT:
<presenter class="net.sf.apptoy.ui.swt.SWTPresenter">
<renderer namespace="http://apptoy.sf.net/swt" class="net.sf.apptoy.ui.swt.SWTRenderer"/>
</presenter>
The presenter class is net.sf.apptoy.ui.SWTPresenter
which is derived from net.sf.apptoy.ui.Presenter . This
class is the abstract parent class for all presenters. New Presenters
for different GUI toolkits may be developped. The core is completely
independent of the used GUI toolkit.
The basic SWT renderer is net.sf.apptoy.ui.SWTRenderer .
It renders all basic SWT widgets.
Extensions to the element set will be done using the renderer
element. New elements must be assigned to their own namespace.
The Script Language (script )
The used script language is defined in the script section. The
example shows the configuration for use with JavaScript:
<script language="javascript">
<mainscript url="apptoy://gui/index.js"/>
<processor default="net.sf.apptoy.script.BSFProcessor"/>
</script>
The BSFProcessor class is an implementation of the Bean
Scripting Framework and is virtually capable of running multiple script
languages. Since BSF allows only basic script functions (enough for
JavaScript), there are a few classes needed to use other languages. In
addition to the correct class, the needed JAR files must be put into the
classpath:
Language |
script example |
JARs in the classpath |
Description |
javascript |
<script language="javascript">
<mainscript url="apptoy://gui/index.js"/>
<processor default="net.sf.apptoy.script.BSFProcessor"/>
</script>
|
js.jar from Mozilla Rhino project |
Javascript is well-known to web developers. It's easy to
implement. On the other hand, usage of own classes is quite limited. |
jython |
<script language="jython">
<mainscript url="apptoy://gui/index.py"/>
<processor default="net.sf.apptoy.script.JythonProcessor">
<module uri="apptoy://gui/presentation.py"/>
<module uri="apptoy://gui/backend.py"/>
</processor>
</script>
|
jython.jar from the Jython project |
Jython modules may be put to any source. They will be downloaded
and compiled to java byte-code when the script is executed. Good for
applications which change frequently because the scripts will be
updated dynamically. |
Java |
<script language="java">
<mainscript
script="net.sf.apptoy.demo.java.DemoModel:start"/>
<processor
default="net.sf.apptoy.script.JavaProcessor"/>
</script>
|
The script class must be in the classpath. |
Java is of course not a scripting language. That's why the script
is not defined as a script file but always as a pair of classname:method .
A class derived from net.sf.apptoy.script.AJavaModel
will be used to call event methods.
With Java, it is not possible to put your scripts on a web server.
The great advantage is the performance and the editor supporting
content assist (which is not the case for most of the script
languages).
|
Other languages can be used as well. Either they can be tried using
the BSFProcessor which knows quite a lot scripting languages. If this
doesn't work it's not too complicated to write your own class derived from
net.sf.apptoy.script.ScriptProcessor to implement your own
scripting engine interface.
|