xml
Class DOMEnlarge

java.lang.Object
  extended by xml.DOMEnlarge

public class DOMEnlarge
extends Object

This class enlarges an input-dom by inserting or deleting attributes, elements, comments, or text nodes. It does that in several layers.

  1. The type of the node to insert has to be specified. It is one of the reserved keywords TYPES.
  2. The value has to be specified. For all except elements this is a single string. For elements, the name of the element has to be specified. The element returned is empty, but it may be piped again to fill it with attributes, text-nodes, comments or additional elements.
  3. The place where the new node should be inserted. Will always refer to an element. This is done in the following way. First, the name of an element may be specified. If the node list returned has more than one entry, then either the node number or the text-value of a first text-child of the element in question may be specified. This procedure can be continued several time.
  4. Attributes are linked as attributes to the specified element. Text nodes are appended as child nodes to the specified element element. Comments and elements are inserted before the specified element. Attribute and text-node amandments may fail if the specified element can not be found. Comments and elements are inserted, regardless of the specified element being locatable.
  5. Inserting the new node is always done for comments and text nodes. Attributes or elements may be specified to replace or leave unchanged.

  6. Nested Class Summary
    static class DOMEnlarge.AddAbort
              A class to add an abort section to the exception element.
    static class DOMEnlarge.AddAbstract
              A class to add the abstract section
    static class DOMEnlarge.AddEmail
              A class to add a e-mail section to all targets.
    static class DOMEnlarge.AddExposure
              A class to add a exposure setup to all targets.
    static class DOMEnlarge.AddExposureBuffer
              A class to add a buffer to the exposure time.
    static class DOMEnlarge.AddFile
              A class to add the file name to the dom.
    static class DOMEnlarge.AddFitsHeader
              A class to add fits-header information to the target files.
    static class DOMEnlarge.AddFitsName
              A class to add fits file names to the targets.
    static class DOMEnlarge.AddFocus
              A class to add a focus setup to all targets.
    static class DOMEnlarge.AddGeometry
              A class to add a geometry setup to all targets.
    static class DOMEnlarge.AddMinimumHeight
              A class to add a minimum height to all targets.
    static class DOMEnlarge.AddSolConstraint
              A class to add fits file names to the targets.
    static class DOMEnlarge.AddTwoExposures
              A class to add a double exposure setup to all targets.
     
    Field Summary
    private static Document dom
              The dom that should be expanded.
    static String[] TYPES
              The allowed types of nodes that are created.
     
    Constructor Summary
    protected DOMEnlarge()
              Constructs a new dom-enlarge object.
     
    Method Summary
    static Node createNode(String type, String data)
              Creates one of the node allowed.
    static Node fillNode(Node target, String value)
              Fills the node with the specified value.
    static Document fromFile(File xml)
              For convenience, a method for loading and parsing an xml-file to a DOM is given.
    static Document getDom()
              Returns the static dom.
    static Object hasSimilar(Element root, Node check)
              Checks if the given element has a node linked to it that is similar to the argument node.
    static Node insertNode(Node root, Node what, Node before)
              Inserts the target node to the given node, before the stated next child.
    static Element scanForElement(Element root, String tag, Object index)
              Scans for elements of the given tag name.
    static void setDom(Document source)
              Sets the source dom.
    static void toFile(Document source, File target)
              For convenience, writes the dom to an xml-file.
     
    Methods inherited from class java.lang.Object
    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
     

    Field Detail

    TYPES

    public static final String[] TYPES
    The allowed types of nodes that are created.


    dom

    private static Document dom
    The dom that should be expanded.

    Constructor Detail

    DOMEnlarge

    protected DOMEnlarge()
    Constructs a new dom-enlarge object. Prior to enlarging the document, the original dom has to be set with setDom(org.w3c.dom.Document).

    Method Detail

    setDom

    public static void setDom(Document source)
    Sets the source dom. If called after several enlargments, all changes are lost.


    createNode

    public static Node createNode(String type,
                                  String data)
    Creates one of the node allowed. TYPES gives a list of names understood by this method. All created nodes are loaded with the data transferred. For element nodes this is the tag-name, for attributes it is the name of the attribute, otherwise it is the value of the node itself.

    Returns:
    null if the type is not recognized or no document is set.

    fillNode

    public static Node fillNode(Node target,
                                String value)
    Fills the node with the specified value. For all except element nodes the string value is set as the node value. If the node is an element, the value is appended as a text child to the element.

    Returns:
    The argument node with the new value filled in.

    scanForElement

    public static Element scanForElement(Element root,
                                         String tag,
                                         Object index)
    Scans for elements of the given tag name. If the given tag name is not found as a sub-node in the stated element node, null is returned. If a single node is encountered, it is returned regardeless of the index argument. If multiple children have been found, then they are scanned, either for number if the index object is an integer, or for text-nodes linked as first childs to the element nodes matching the index string. If this search is not successful, null is returned.


    hasSimilar

    public static Object hasSimilar(Element root,
                                    Node check)
    Checks if the given element has a node linked to it that is similar to the argument node. If the argument node is an attribute, the element is checked for having an attribute of the same name. If so, true is returned. If the argument itself is an element, the root is checked if it has child-nodes with the tag name of the stated element. Again, true is returned in that case.

    Returns:
    Null if no match was found, a single attribute node if an attribute of the same name was found or a node list if check was for an element.

    insertNode

    public static Node insertNode(Node root,
                                  Node what,
                                  Node before)
    Inserts the target node to the given node, before the stated next child.

    Parameters:
    what - If attribute, set as attribute to root
    before - If null, append to children list of root.
    Returns:
    The inserted node.

    getDom

    public static Document getDom()
    Returns the static dom.


    fromFile

    public static Document fromFile(File xml)
    For convenience, a method for loading and parsing an xml-file to a DOM is given. It is validating, does not ignore comments, but whitespace nodes, coalesces, but does not expand entities.


    toFile

    public static void toFile(Document source,
                              File target)
    For convenience, writes the dom to an xml-file.