Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
At this point, we only need to implement code within the saveConfiguration( ) method to update the XML document with the modified member variable values. This can be done completely with the JDOM APIs, using the Document object we loaded and saved a reference to when parsing the XML document, as well as the supplied OutputStream (which, in our example, is actually a FileOutputStream wrapping a file on the filesystem). Once updates are made, we need to update that Document object, and then write the changes out to a file. In other applications, the modified Document could be transformed with XSLT and output as HTML or another markup language, or passed on to another application over a network.
All that is left to make our application fully functional is to add code to the saveConfiguration( ) method that takes in an OutputStream as an argument, as this is called by the version that takes a String filename as a parameter. Since we saved a reference to the Document object, this is simply a matter of setting the content of the various elements that are modified through the setContent( ) method available on Element instances. We can first handle the hostname, port, and parserClass elements, which are nested directly within the root element: