edu.northwestern.at.morphadorner.tools.compareadornedfiles

## Class MutableAdornedFile

- java.lang.Object
- - edu.northwestern.at.morphadorner.tools.compareadornedfiles.MutableAdornedFile

-     public class MutableAdornedFile
      extends java.lang.Object

  Loads an adorned XML file for updating.

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected java.util.Map<java.lang.String,org.jdom2.Element>` | `adornedWordMap` Map from word ID to adorned word elements.
    `protected org.jdom2.Document` | `document` Adorned document.
    `protected static org.jdom2.Namespace` | `teiNamespace` TEI name space.
    `protected java.util.List<java.lang.String>` | `wordIDs` List of word IDs.
    `protected java.util.Set<java.lang.String>` | `wordTagsSet` Set of word tags (typically "w" and "pc").

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `MutableAdornedFile(java.lang.String adornedFileName)` Create mutable adorned file.
    `MutableAdornedFile(java.lang.String adornedFileName, java.lang.String[] wordTags)` Create mutable adorned file.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected void` | `addWordElement(java.lang.String id, java.lang.String siblingID, java.lang.String text, boolean blankPrecedes)` Add word element.
    `void` | `applyChange(WordChange change)` Apply a change from a change log.
    `void` | `applyChanges(java.util.List<WordChange> changes)` Apply changes from a change log.
    `protected void` | `compressCElements()` Compress "" elements.
    `protected org.jdom2.Element` | `createElement(java.lang.String name)` Create an element.
    `protected boolean` | `deleteWordElement(java.lang.String id)` Delete a word element.
    `void` | `deleteWordElementAttribute(java.lang.String id, java.lang.String attrName)` Delete a word element attribute.
    `org.jdom2.Element` | `getAdornedWord(java.lang.String id)` Get element for a specified word ID.
    `java.util.List<java.lang.String>` | `getAdornedWordIDs()` Return list of word IDs.
    `org.jdom2.Document` | `getDocument()` Get document.
    `void` | `revertChange(WordChange change)` Revert a change from a change log.
    `void` | `revertChanges(java.util.List<WordChange> changes)` Revert changes from a change log.
    `void` | `setWordElementAttribute(java.lang.String id, java.lang.String attrName, java.lang.String attrValue)` Set word element attribute value.
    `void` | `setWordElementText(java.lang.String id, java.lang.String text)` Set word element text.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### adornedWordMap

          protected java.util.Map<java.lang.String,org.jdom2.Element> adornedWordMap

      Map from word ID to adorned word elements.

    - #### wordIDs

          protected java.util.List<java.lang.String> wordIDs

      List of word IDs.

    - #### wordTagsSet

          protected java.util.Set<java.lang.String> wordTagsSet

      Set of word tags (typically "w" and "pc").

    - #### document

          protected org.jdom2.Document document

      Adorned document.

    - #### teiNamespace

          protected static org.jdom2.Namespace teiNamespace

      TEI name space.

  - ### Constructor Detail

    - #### MutableAdornedFile

          public MutableAdornedFile(java.lang.String adornedFileName,
                            java.lang.String[] wordTags)
                             throws java.lang.Exception

      Create mutable adorned file.
      Parameters:
        `adornedFileName` - The adorned file.
        `wordTags` - String array of word tag element names, typically "w" and "pc".
      Throws:
        `java.lang.Exception` - in case of error.

    - #### MutableAdornedFile

          public MutableAdornedFile(java.lang.String adornedFileName)
                             throws java.lang.Exception

      Create mutable adorned file.
      Parameters:
        `adornedFileName` - The adorned file from which to load word data.
      Throws:
        `java.lang.Exception` - in case of error.

        The word elements are assumed to be tagged as and .

  - ### Method Detail

    - #### getAdornedWordIDs

          public java.util.List<java.lang.String> getAdornedWordIDs()

      Return list of word IDs.
      Returns:
        list of word IDs.

    - #### getAdornedWord

          public org.jdom2.Element getAdornedWord(java.lang.String id)

      Get element for a specified word ID.
      Parameters:
        `id` - Word ID.
      Returns:
        The word element, or null if the word ID does not exist.

    - #### getDocument

          public org.jdom2.Document getDocument()

      Get document.
      Returns:
        The updated document.

    - #### applyChange

          public void applyChange(WordChange change)

      Apply a change from a change log.
      Parameters:
        `change` - The change to apply.

    - #### revertChange

          public void revertChange(WordChange change)

      Revert a change from a change log.
      Parameters:
        `change` - The change to revert.

    - #### applyChanges

          public void applyChanges(java.util.List<WordChange> changes)

      Apply changes from a change log.
      Parameters:
        `changes` - The changes to apply.

    - #### revertChanges

          public void revertChanges(java.util.List<WordChange> changes)

      Revert changes from a change log.
      Parameters:
        `changes` - The changes to revert.

    - #### createElement

          protected org.jdom2.Element createElement(java.lang.String name)

      Create an element.
      Parameters:
        `name` - Element name.

    - #### deleteWordElement

          protected boolean deleteWordElement(java.lang.String id)

      Delete a word element.
      Parameters:
        `id` - Word ID of element to delete.
      Returns:
        true if delete, false otherwise.

    - #### deleteWordElementAttribute

          public void deleteWordElementAttribute(java.lang.String id,
                                        java.lang.String attrName)

      Delete a word element attribute.
      Parameters:
        `id` - Word ID of element for which to delete attribute.
        `attrName` - Name of attribute to delete.

    - #### setWordElementText

          public void setWordElementText(java.lang.String id,
                                java.lang.String text)

      Set word element text.
      Parameters:
        `id` - Word ID of element.
        `text` - The word text.

    - #### setWordElementAttribute

          public void setWordElementAttribute(java.lang.String id,
                                     java.lang.String attrName,
                                     java.lang.String attrValue)

      Set word element attribute value.
      Parameters:
        `id` - Word ID of element.
        `attrName` - The attribute name.
        `attrValue` - The attribute value.

    - #### addWordElement

          protected void addWordElement(java.lang.String id,
                            java.lang.String siblingID,
                            java.lang.String text,
                            boolean blankPrecedes)

      Add word element.
      Parameters:
        `id` - Word ID of element to add.
        `siblingID` - Word ID of sibling element.
        `text` - The word text.

    - #### compressCElements

          protected void compressCElements()

      Compress "" elements.

      Deleting words may have left sequences of " ..." elements. Each such sequence should be compressed to a single " " element.