Class Component

  • Direct Known Subclasses:
    Row, Table, TextContainer

    public class Component
    extends Object
    The component is a logical modular entity, to abstract from the implementation details of the XML.
    Author:
    svante.schubertATgmail.com
    • Constructor Detail

      • Component

        public Component​(OdfElement componentElement)
        Only being used to create the root of all components, representing the document without a parent element
    • Method Detail

      • isComponentRoot

        public static boolean isComponentRoot​(Element element)
        Tests if the given element is the start of a component
        Returns:
        true if the given element is the root of an ODF component
      • isComponentRoot

        public static boolean isComponentRoot​(String uri,
                                              String localName)
        Tests if the given element is the start of a component
        Returns:
        true if the given element is the root of an ODF component
      • isComponentWrapper

        public static boolean isComponentWrapper​(Element element)
        Tests if the given element is the wrapper around a descendant component root element
        Returns:
        true if the given element is a potential wrapper around an ODF component
      • isComponentWrapper

        public static boolean isComponentWrapper​(String uri,
                                                 String localName)
        Tests if the given element is the wrapper around a descendant component root element
        Returns:
        true if the given element is a potential wrapper around an ODF component
      • isTextComponentRoot

        public static boolean isTextComponentRoot​(Node textContainer)
        Returns true if the Node is an TextPElement or TextHElement. Both are the root elements of text containers. Text container have special handline of whitespace, see http://docs.oasis-open.org/office/v1.2/os/OpenDocument-v1.2-os-part1.html#White-space_Characters
      • isTextComponentRoot

        public static boolean isTextComponentRoot​(String uri,
                                                  String localName)
      • isRowComponentRoot

        public static boolean isRowComponentRoot​(Node textContainer)
      • isRowComponentRoot

        public static boolean isRowComponentRoot​(String uri,
                                                 String localName)
      • isField

        public static boolean isField​(String uri,
                                      String localName)
      • isDocumentRoot

        public static boolean isDocumentRoot​(String uri,
                                             String localName)
        Tests if the given element is the start of a document
        Returns:
        true if the given element is the root of an ODF document (e.g. office:text)
      • isHeaderRoot

        public static boolean isHeaderRoot​(String uri,
                                           String localName)
        Tests if the given element is the start of a header within a page style. The content of a header is equal to the content of a usual ODT text file (ie. ).
        Returns:
        true if the given element is the root of a header (i.e. style:header)
      • isFooterRoot

        public static boolean isFooterRoot​(String uri,
                                           String localName)
        Tests if the given element is the start of a footer within a page style. The content of a footer is equal to the content of a usual ODT text file (ie. ).
        Returns:
        true if the given element is the root of a footer (i.e. style:footer)
      • isShapeElement

        public static boolean isShapeElement​(String uri,
                                             String localName)
        Tests if the given element is a shape element Shapes are in general those with elements with a
        Returns:
        true if the given element is the root of an ODF shape element
      • isWhiteSpaceElement

        public static boolean isWhiteSpaceElement​(String uri,
                                                  String localName)
        Tests if the given element is a whitespace element
        Returns:
        true if the given element is an ODF whitespace element
      • isCoveredComponentRoot

        public static boolean isCoveredComponentRoot​(String uri,
                                                     String localName)
      • isTextSelection

        public static boolean isTextSelection​(Node textSelection)
        Returns:
        true if the node is a text delimiter element
      • getParent

        public Component getParent()
        Returns the parent component
      • getCorrectStartElementOfChild

        public static OdfElement getCorrectStartElementOfChild​(OdfElement parentElement,
                                                               OdfElement existingChildElement)
        Sometimes (e.g. if the child is a paragraph within list elements). The parent root element of the child component root element will not be directly children. It will be checked if there is a child element or list level 10 has reached.
      • getLastChild

        public Component getLastChild()
      • getOwnerDocument

        public Document getOwnerDocument()
      • getChildNode

        public Node getChildNode​(int position)
        Returns:
        the child at the given position
      • get

        public Component get​(org.json.JSONArray position)
      • get

        protected Component get​(org.json.JSONArray position,
                                boolean needParent,
                                boolean needFollowingSibling,
                                int depth)
        Get descendant component by its relative position to this component. Counting starts with 0.
        Parameters:
        position - relative position of the desired component relative to the current component
        needParent - if true the parent of the given position is returned
        needFollowingSibling - if true the next sibling of the given position is returned (exclusive to getPositionsFollowingSibling)
      • getNextSiblingOf

        public Component getNextSiblingOf​(org.json.JSONArray position)
        Get next sibling component of the given position. Counting start with 0.
      • getParentOf

        public Component getParentOf​(org.json.JSONArray position)
        Get parent component of the given position
      • getRootComponent

        public Component getRootComponent()
      • getRootElement

        public OdfElement getRootElement()
        Returns:
        the root element of the component
      • createChildComponent

        public Component createChildComponent​(OdfElement componentRoot)
        Appending a child element to the component
      • createChildComponent

        public static Component createChildComponent​(int position,
                                                     Component parentComponent,
                                                     OdfElement newChildElement)
        Inserts a component at the given position as child
        Parameters:
        position - of the component, a -1 is going to append the element
      • addChild

        public void addChild​(int index,
                             Component c)
        Adds the given component as new child component. No XML elements are being changed!
        Parameters:
        index - starting with 0 representing the position of the child, if -1 the new child will be appended
      • remove

        public Node remove​(int position)
        Only removes from the component list, not from the DOM
      • size

        public int size()
        Returns the number of child components
      • hasRepeated

        public void hasRepeated​(boolean hasRepeated)
      • hasRepeated

        public boolean hasRepeated()
      • getPosition

        protected String getPosition​(Component c)
        Returns:
        the position as a slash separated string
      • getPositionString

        protected static String getPositionString​(Component c)
        Returns:
        the position as a slash separated string
      • indexOf

        public int indexOf​(Object o)
      • getMainStyleGroupingId

        public static String getMainStyleGroupingId​(OdfStyleFamily styleFamily)
      • getFamilyName

        public static String getFamilyName​(String styleId)
        Returns:
        styleFamilyValue the String value * * * * * * * of StyleFamilyAttribute,
      • getFamily

        public static OdfStyleFamily getFamily​(String styleId)
        Returns:
        styleFamily the OdfStyleFamily representation * * * of StyleFamilyAttribute,
      • repetition

        public int repetition()
        A multiple components can be represented by a single XML element
        Returns:
        the number of components the elements represents