Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## ix.util.xml
Class XMLSaver

    java.lang.Object
      ix.util.xml.XMLSaver

    public class XMLSaver

extends java.lang.Object

A utility for saving objects and XML documents to files, conducting dialogs as required. Objects can be saved in a variety of syntaxes, not only as XML. The available syntaxes are determined from the object's class by a `FileSyntaxManager`.

See Also:
  `XML.fileSyntaxManager()`

Field Summary
`protected javax.swing.JFileChooser` | `fileChooser`
`protected java.awt.Component` | `frame`
`protected java.io.File` | `libDir`
`protected java.lang.Class` | `outputObjectClass`
`protected XMLTranslator` | `xmlt`

Constructor Summary
`XMLSaver(java.awt.Component frame)` Creates an XMLSaver that uses the default XML translator that is in force at the time this constructor is called.
`XMLSaver(java.awt.Component frame, java.lang.Class outputObjectClass)`

Method Summary
`protected java.io.File` | `agreeFileToWrite()` Asks the user to select a file and, if it already exists, whether to overwrite it.
`protected java.io.File` | `chooseFileToWrite()` Asks the user to choose a file.
`XMLTranslator` | `getXMLTranslator()` Returns the XMLTranslator that is used by the saveObject method to translate an object to a JDOM document.
`javax.swing.JFileChooser` | `makeFileChooser()` Constructs a suitable file-chooser for this XMLSaver's output object class.
`void` | `saveDocument(org.jdom.Document doc)` Writes a JDOM Document to a file selected by the user, conducting any necessary dialogs along the way.
`void` | `saveObject(java.lang.Object obj)` Writes an object to a file in a form that corresponds to the selected file type or extension, conducting any necessary dialogs along the way.
`void` | `setXMLTranslator(XMLTranslator xmlt)` Sets the XMLTranslator that is used by this XMLSaver to translate an object to a JDOM document.
`protected void` | `writeDocumentTo(java.io.File file, org.jdom.Document doc)` Writes the document to the file.
`protected void` | `writeObjectToFile(java.lang.Object obj, java.io.File file)`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### libDir

    protected java.io.File libDir

### xmlt

    protected XMLTranslator xmlt

### fileChooser

    protected javax.swing.JFileChooser fileChooser

### frame

    protected java.awt.Component frame

### outputObjectClass

    protected java.lang.Class outputObjectClass

Constructor Detail

### XMLSaver

    public XMLSaver(java.awt.Component frame)

  Creates an XMLSaver that uses the default XML translator that is in force at the time this constructor is called.

  See Also:
    `XML.defaultTranslator()`

### XMLSaver

    public XMLSaver(java.awt.Component frame,
                    java.lang.Class outputObjectClass)

Method Detail

### getXMLTranslator

    public XMLTranslator getXMLTranslator()

  Returns the XMLTranslator that is used by the saveObject method to translate an object to a JDOM document.

### setXMLTranslator

    public void setXMLTranslator(XMLTranslator xmlt)

  Sets the XMLTranslator that is used by this XMLSaver to translate an object to a JDOM document.

### saveObject

    public void saveObject(java.lang.Object obj)

  Writes an object to a file in a form that corresponds to the selected file type or extension, conducting any necessary dialogs along the way. It repeatedly asks the user to select a file until either the object has been successfully written or the user decides to cancel the operation. The user is informed of any exceptions thrown while attempting to write, and "success" means that no exceptions were thrown.

  The default is to Convert the object to a JDOM Document and then call the saveDocument method.

  See Also:
    `saveDocument(Document)`, `agreeFileToWrite()`

### writeObjectToFile

    protected void writeObjectToFile(java.lang.Object obj,
                                     java.io.File file)
                              throws java.io.IOException

  Throws:
    `java.io.IOException`

### saveDocument

    public void saveDocument(org.jdom.Document doc)

  Writes a JDOM Document to a file selected by the user, conducting any necessary dialogs along the way. It repeatedly asks the user to select a file until either the Document has been successfully written or the user decides to cancel the operation. The user is informed of any exceptions thrown while attempting to write, and "success" means that no exceptions were thrown.

  See Also:
    `saveObject(Object)`, `agreeFileToWrite()`

### writeDocumentTo

    protected void writeDocumentTo(java.io.File file,
                                   org.jdom.Document doc)
                            throws java.io.IOException

  Writes the document to the file.

  Throws:
    `java.io.IOException`
  See Also:
    `XML.makePrettyXMLOutputter()`

### agreeFileToWrite

    protected java.io.File agreeFileToWrite()

  Asks the user to select a file and, if it already exists, whether to overwrite it. If the user decides to overwrite an existing file, the current version will first be renamed; if the user decides not to overwrite, he or she will be asked to select a different file. This continues until either the user has agreed to a file or else has elected to cancel. #see Util#renameToBackup(File)

### chooseFileToWrite

    protected java.io.File chooseFileToWrite()

  Asks the user to choose a file. Returns null if the user cancels.

### makeFileChooser

    public javax.swing.JFileChooser makeFileChooser()

  Constructs a suitable file-chooser for this XMLSaver's output object class.

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD