edu.northwestern.at.wordhoard.swing.calculator.modelutils
Class ImportUtils

java.lang.Object
  extended by edu.northwestern.at.wordhoard.swing.calculator.modelutils.ImportUtils

public class ImportUtils
extends java.lang.Object

Utilities for importing user-defined database objects from XML.


Field Summary
protected static FileExtensionFilter xmlFilter
          XML extension file filter.
 
Constructor Summary
protected ImportUtils()
          Don't allow instantiation but do allow overrides.
 
Method Summary
static org.w3c.dom.Document getImportDocument(java.lang.String importFileName)
          Parse import xml file to DOM document.
static java.lang.String getImportFileName(java.awt.Window parentWindow)
          Get name of import file.
static boolean importObjects(UserDataObject[] objects, boolean[] importedOK, boolean renameDuplicates, ProgressReporter progressReporter)
          Import a list of objects from DOM document.
static boolean isDuplicate(UserDataObject object)
          Check for a duplicate import item.
protected static boolean persistImportedObject(UserDataObject object)
          Persist an imported object.
static void renameDuplicate(UserDataObject object)
          Rename a duplicate import item.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

xmlFilter

protected static FileExtensionFilter xmlFilter
XML extension file filter.

Constructor Detail

ImportUtils

protected ImportUtils()
Don't allow instantiation but do allow overrides.

Method Detail

getImportFileName

public static java.lang.String getImportFileName(java.awt.Window parentWindow)
Get name of import file.

Parameters:
parentWindow - Parent window for file dialog.
Returns:
Name of import XML file, or null if none given.

getImportDocument

public static org.w3c.dom.Document getImportDocument(java.lang.String importFileName)
Parse import xml file to DOM document.

Parameters:
importFileName - The name of the xml file containing the WordHoard items to import.
Returns:
The document. Null if parse fails.

isDuplicate

public static boolean isDuplicate(UserDataObject object)
Check for a duplicate import item.

Parameters:
object - The object to import.
Returns:
true if object duplicates name of existing object.

renameDuplicate

public static void renameDuplicate(UserDataObject object)
Rename a duplicate import item.

Parameters:
object - The object to import.

persistImportedObject

protected static boolean persistImportedObject(UserDataObject object)
Persist an imported object.

Parameters:
object - The imported object to persist.

Handles any special persistence needs for different types of user data objects.


importObjects

public static boolean importObjects(UserDataObject[] objects,
                                    boolean[] importedOK,
                                    boolean renameDuplicates,
                                    ProgressReporter progressReporter)
                             throws ImportException
Import a list of objects from DOM document.

Parameters:
objects - Objects to import.
importedOK - Array of booleans of same length as objects. On output each element will be set true if the corresponding object was successfully persisted, false otherwise.
renameDuplicates - Rename duplicate items. Items whose names already appear in the database will not be persisted unless renameDuplicates is true.
progressReporter - Progress reporter.
Returns:
true if all objects imported, false otherwise.

When renameDuplicates is true, the name of an import item which duplicates an existing item name of the same type will be changed to a non-duplicate name. The modified item name is constructed by appending "-n" to the existing item name, where "n" is an integer starting at 1.

Throws:
ImportException