Developer's Guide to Flying Saucer

Getting control of loading data - UserAgentCallback

Loading of documents, stylesheets and images is under the control of the user agent (i.e. your code).

To get control of these things you need to implement the org.xhtmlrenderer.extend.UserAgentCallback interface and pass it to the constructor of one of the panels or your extension of a panel.

By default, the panels use org.xhtmlrenderer.swing.NaiveUserAgent which just loads everything. If you wish, you may of course extend this class and override the stuff that you care about.

To build a general web-browser, you will need to make an implementation that converts crappy html to good xml. Then you should probably make a NamespaceHandler (see below) to turn html styling attributes into css element styles. Alternatively, the document could first be converted to good css-styled xhtml.

Handling different document types - NamespaceHandler

The Flying Saucer xhtmlrenderer in its basic form just renders xml styled with css. The stylesheet is obtained from an <?xml-stylesheet?> processing-instruction. There is no inherent knowledge of the document type, other than what is known about xml as such.

Knowledge about a document type is provided through the NamespaceHandler interface. An implementation of this interface may be provided in the method public void setDocument(Document doc, URL url, NamespaceHandler nsh)

The BasicPanel will by default use the org.xhtmlrenderer.swing.NoNamespaceHandler implementation.

The XHTMLPanel will by default use the org.xhtmlrenderer.simple.extend.XhtmlNamespaceHandler implementation.

The provided NamespaceHandler will be able to provide a JComponent to replace any element. At the time of this writing the element needs to have a display property set to "inline-block" for this to work. Anyway, with the right NamespaceHandler and UserAgentCallback, you could do just about anything, like, for example, make a XUL implementation on top of Flying Saucer.

Receiving Document Events

if you want to know when the document is loaded you'll need to implement the org.xhtmlrenderer.event.DocumentListener interface, which currently only has one method: documentLoaded()

Using the FSScrollPane

Since an XHTMLPanel is a JComponent you can put it inside of a JScrollPane to implement scrolling. It behaves just as a JTable or JList would. However, Flying Saucer provides the FSScrollPane to implement more intelligent scrolling such as moving down a line when you press the down arrow key and moving down by a whole page when you hit the page down key. For more information see the javadocs for FSScrollPane.