Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

12.2. Modifying the Data

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.

12.2.1. Updating the Configuration Information

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:


  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial