xelem.3.0

nl.fountain.xelem
Class XFactory

java.lang.Object
  extended by nl.fountain.xelem.XFactory

public class XFactory
extends Object

An intermediary to the configuration file, it's main productline being SpreadsheetML Style elements. An instance of this class may be obtained by calling the newInstance()-method.

Normally this class expects a configuration file at the location config/xelem.xml, relative to the classloader of the main application. If desired a different location may be set by calling setConfigurationFileName(String) prior to obtaining a new instance.

At the first call to newInstance() the XFactory parses the configuration file and loads comments and styles from it. The XFactory can be used to merge styles.

See Also:
overview - the XFactory

Method Summary
 boolean addStyle(Element style)
          Add a new SpreadsheetML Style element to the factory.
 void appendInfoSheet(Element root, GIO gio)
          Appends a Worksheet element with general information to the root element.
static XFactory emptyFactory()
          Gets a new empty instance of this class; all existing instances of this class will be empty after calling this method.
static String getConfigurationFileName()
          Gets the file name of the configuration file.
 List<String> getDocComments()
          Gets a list of Strings which represent the node values of the tag <f:comment> in the configuration file.
 Element getStyle(String id)
          Gets the SpreadsheetML Style element with the ss:StyleID id.
 Set<String> getStyleIDs()
          Gets a set of ss:ID's (String) of all the available styles in the factory.
 int getStylesCount()
          Gets the number of available styles in the factory.
 void mergeStyles(String newID, String id1, String id2)
          Merges two SpreadsheetML Style elements.
static XFactory newInstance()
          Gets an instance of this class.
static void reset()
          Resets the static configuration and configuration file name.
static void setConfigurationFileName(String fileName)
          Sets path and file name of the configuration file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

newInstance

public static XFactory newInstance()
                            throws XelemException
Gets an instance of this class.

Returns:
an instance of this class
Throws:
XelemException - could be caused by:

emptyFactory

public static XFactory emptyFactory()
Gets a new empty instance of this class; all existing instances of this class will be empty after calling this method. If a configuration file name was previously set, this will no longer hold.

Returns:
new empty instance of this class

setConfigurationFileName

public static void setConfigurationFileName(String fileName)
Sets path and file name of the configuration file. This method may be invoked if a configuration file is used other than the one at config/xelem.xml. The file name must be absolute or relative to the classloader of the main application.

Parameters:
fileName - The file name (may include path) of the configuration file.

getConfigurationFileName

public static String getConfigurationFileName()
Gets the file name of the configuration file. If no configuration file was set previously, returns the default configuration file name: config/xelem.xml.

Returns:
the file name (may include path) of the configuration file

reset

public static void reset()
Resets the static configuration and configuration file name. Changes in the configuration file config/xelem.xml will be reflected in a new instance.


getDocComments

public List<String> getDocComments()
Gets a list of Strings which represent the node values of the tag <f:comment> in the configuration file. If no comments are present the list may be empty.

Returns:
a list of Strings

getStyle

public Element getStyle(String id)
Gets the SpreadsheetML Style element with the ss:StyleID id. The Style element was either present in the configuration file or was previously merged with the method mergeStyles.

Parameters:
id - The ss:ID attribute-value of the wanted style.
Returns:
A Style element. May be null if the wanted style is unknown to the factory.

getStylesCount

public int getStylesCount()
Gets the number of available styles in the factory.

Returns:
the number of available styles.

getStyleIDs

public Set<String> getStyleIDs()
Gets a set of ss:ID's (String) of all the available styles in the factory.

Returns:
all available style id's.

mergeStyles

public void mergeStyles(String newID,
                        String id1,
                        String id2)
                 throws UnsupportedStyleException
Merges two SpreadsheetML Style elements. If a style element with the ss:ID newID allready was present in the factory, nothing happens.
Creates a copy of style 1 and appends those child elements of style 2 that were previously not defined in style 1. Any ss:Name attribute is removed from the copy. The copy is given the ss:ID newID and is from now on availlable by the method getStyle(newID).

Parameters:
newID - the ss:ID of the new merged style
id1 - the ss:ID of the copied style
id2 - the ss:ID of the appended style
Throws:
UnsupportedStyleException - if either of the styles mentioned with id1 or id2 are unknown to the factory.

addStyle

public boolean addStyle(Element style)
Add a new SpreadsheetML Style element to the factory. If the factory allready contains an element with the same ss:ID as the passed element, no element will be added and the method returns false.

Parameters:
style - a SpreadsheetML style element
Returns:
true if the style element was succesfully added, false otherwise
Throws:
NullPointerException - if the passed style did not have an attribute ss:ID

appendInfoSheet

public void appendInfoSheet(Element root,
                            GIO gio)
                     throws XelemException
Appends a Worksheet element with general information to the root element. Adds all used styles in the info sheet to the factory and their id's to the gio.

Parameters:
root - the root element.
gio - the GIO used while assembling the Workbook.
Throws:
XelemException - if the info sheet could not be loaded.
See Also:
Workbook.appendInfoSheet()

xelem.3.0