The HTML Browser grammar is an example for visualizing a directory
tree and browsing HTML files.
This grammar performs a recursive scan of a directory of your filesystem
for HTML files and represents the directory tree as a graph.
Afterwards, it starts up an HTML browser to inspect the files that have been found.
The files already visited are marked in the graph.
This example demonstrates how you can access system resources like
the file system using user-defined Java classes and their methods in graph rules.
It also shows how you can control an external Java application
(here: the browser) by graph transformation rules.
Figure 8 shows rule initDir
being applied to the
start graph of grammar HTML_Browser. The rule launchs
a dialog asking for the directory to browse.
Here the user-defined Java class Entry (Entry.java) is used for attribute name in the right-hand side of the rule.
This class defines operations for:
Also rules showDir, prepare2ndPath and showFile
invoke methods of this class.
Rule openBrowser in Figure 9 uses another user-defined Java class
Browser (Browser.java)
to create a file browser.
Finally, rule viewPage in Figure 10 uses class Browser to view a HTML file. Please pay attention to the attribution of ref in the Browser node in the RHS of the rule. The method setPage of class Browser returns no object (is void) but we want to return. In this case we use (semicolon) to return the changed Browser object ( ).
Please note: A user-defined class has to contain the default class constructor without parameters. If a class rewrites the default class constructor, the first line has to contain super(); entry. Moreover, setter and getter methods have to be defined for class parameters like this: for a parameter with the name abc the setter and getter methods will get the names setAbc(...) and getAbc(). The method toString() can be rewritten to get a sufficient string representation of this class.