|
DOM ExampleIf you are not yet familiar with WBI's new MegObject feature, have a look at the simple MegObject example. Try It Out
What It DoesThe DomExample uses an implementation of MegObject that encapsulates a DOM. Three Megs work on this DOM to transform webpages into "low media" pages.
How It Works
ArchitectureThe DomExample plugin edits retrieved web pages (removing color information and images) before the pages are shown to the user. The MEGs rely on a simple implementation of MegObject to work together directly through a DOM rather than working from the byte stream. MEG ModelThis plugin sets up three HttpEditors that work on a DomMegObject. To avoid reparsing the stream, their priorities are set to the same value. Although this does not guarantee that no other MEG might interfere, the probability that no MEG will is high. If you write a plugin that uses the DomMegObject, you would want to give your MEGs the same priority as this plugin does. If your plugin does not use the same DomMegObject implementation, you should probably use another priority.
Implementation DetailsThis plugin relies heavily on the DomMegObject. This is a MegObject that encapsulates a org.w3c.dom.Document. Of special interest is its public constructor which takes a RequestEvent as an argument. While in the MegObjectExample plugin, each MEG had to examine the RequestEvent in order to get or create the MegObject, this now lies in the responsibility of the DomMegObject. The MEGs now can very easily obtain a DomMegObject. HTML is no subset of XML and that means that HTML documents are not easily parsed into a DOM. For this example plugin we used the JTidy implementation which does a great job but is still not perfect. If you would like to use a different parser, wrap it into Html2DomParser and call DomMegObject's setParser() method. DOM to HTML conversion is easier but still some pitfalls apply. XmlWriter is a helper class that converts a DOM into a stream.
As you can see, a MegObject implementation offers three functionalities:
The three Editors simply create a DomMegObject from the RequestEvent, recurse through its DOM, change some nodes and put the DomMegObject back into the RequestEvent. Without the DomMegObject, each MEG would have to parse the HTML document by itself and write each of the bytes back out to the stream, a very expensive process. Some key WBI classes that were used:
Known Problems
Source Files
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||