Class OdfElement

    • Method Detail

      • getOdfName

        public abstract OdfName getOdfName()
      • getParentAs

        protected <T extends OdfElement> T getParentAs​(Class<T> clazz)
      • getAncestorAs

        protected <T extends OdfElement> T getAncestorAs​(Class<T> clazz)
      • hasAncestor

        public boolean hasAncestor​(Node potentialParent)
      • toString

        public String toString()
        Overrides:
        toString in class org.apache.xerces.dom.NodeImpl
      • setOdfAttributeValue

        public void setOdfAttributeValue​(OdfName name,
                                         String value)
        Set the value of an ODF attribute by OdfName.
        Parameters:
        name - The qualified name of the ODF attribute.
        value - The value to be set in String form
      • setOdfAttribute

        public void setOdfAttribute​(OdfAttribute attribute)
        Set an ODF attribute to this element
        Parameters:
        attribute - the attribute to be set
      • getOdfAttributeValue

        public String getOdfAttributeValue​(OdfName name)
        Retrieves a value of an ODF attribute by OdfName.
        Parameters:
        name - The qualified name of the ODF attribute.
        Returns:
        The value of the attribute as String or null if the attribute does not exist.
      • getOdfAttribute

        public OdfAttribute getOdfAttribute​(OdfName name)
        Retrieves an ODF attribute by OdfName.
        Parameters:
        name - The qualified name of the ODF attribute.
        Returns:
        The OdfAttribute or null if the attribute does not exist.
      • getOdfAttribute

        public OdfAttribute getOdfAttribute​(NamespaceName namespace,
                                            String localname)
        Retrieves an ODF attribute by NamespaceName, and local name.
        Parameters:
        namespace - The namespace of the ODF attribute.
        localname - The local name of the ODF attribute.
        Returns:
        The OdfAttribute or null if the attribute does not exist.
      • hasOdfAttribute

        public boolean hasOdfAttribute​(OdfName name)
        Determines if an ODF attribute exists.
        Parameters:
        name - The qualified name of the ODF attribute.
        Returns:
        True if the attribute exists.
      • findFirstChildNode

        public static <T extends OdfElement> T findFirstChildNode​(Class<T> clazz,
                                                                  Node parentNode)
        returns the first child node that implements the given class.
        Type Parameters:
        T - The type of the ODF element to be found.
        Parameters:
        clazz - is a class that extends OdfElement.
        parentNode - is the parent O of the children to be found.
        Returns:
        the first child node of the given parentNode that is a clazz or null if none is found.
      • findNextChildNode

        public static <T extends OdfElement> T findNextChildNode​(Class<T> clazz,
                                                                 Node refNode)
        returns the first sibling after the given reference node that implements the given class.
        Type Parameters:
        T - The type of the ODF element to be found.
        Parameters:
        clazz - is a class that extends OdfElement.
        refNode - the reference node of the siblings to be found.
        Returns:
        the first sibling of the given reference node that is a class or null if none is found.
      • findPreviousChildNode

        public static <T extends OdfElement> T findPreviousChildNode​(Class<T> clazz,
                                                                     Node refNode)
        returns the first previous sibling before the given reference node that implements the given class.
        Parameters:
        clazz - is a class that extends OdfElement.
        refNode - the reference node which siblings are to be searched.
        Returns:
        the first previous sibling of the given reference node that is a class or null if none is found.
      • cloneElement

        public OdfElement cloneElement()
        Clones this complete element with all descendants.
        Returns:
        the cloned element
      • cloneOdfElement

        protected OdfElement cloneOdfElement()
        Overwritten by AlienElement class, which represents XML elements of various names
      • cloneNode

        public Node cloneNode​(boolean deep)
        Specified by:
        cloneNode in interface Node
        Overrides:
        cloneNode in class org.apache.xerces.dom.ElementImpl
      • cloneNode

        public Node cloneNode​(int depth)
        Parameters:
        depth - how many levels of children should be considered
        Returns:
        the cloned node (element)
      • cloneNode

        public static OdfElement cloneNode​(OdfElement source,
                                           OdfElement target,
                                           boolean deep)
        Clones the content of the source element including attributes even xml:id to the target element. Helpful when changing a to a and vice versa, when outline attribute changes.
        Parameters:
        source - the element to copy the content & attributes from.
        target - the element to copy the content & attributes into.
        deep - if a deep copy should happen. If false only the source element attributes will be copied, otherwise all descendants.
        Returns:
        the target element with all new nodes
      • appendChild

        public Node appendChild​(Node node)
        Specified by:
        appendChild in interface Node
        Overrides:
        appendChild in class org.apache.xerces.dom.NodeImpl
      • componentSize

        public int componentSize()
        Recursive traverse the text container and count the size of the content
      • equals

        public boolean equals​(Object obj)
        indicates if some other object is equal to this one.
        Overrides:
        equals in class Object
        Parameters:
        obj - - the reference object with which to compare.
        Returns:
        true if this object is the same as the obj argument; false otherwise.
      • onRemoveNode

        protected void onRemoveNode​(Node node)
      • onInsertNode

        protected void onInsertNode​(Node node)
      • onRemoveNode

        protected void onRemoveNode()
      • onInsertNode

        protected void onInsertNode()
      • isRepeatable

        public boolean isRepeatable()
        Returns:
        true if the element does represent multiple instances. (only applicable for some elements as cell or row).
      • getRepetition

        public int getRepetition()
        Returns:
        the repetition the element represents, by default it is 1
      • removeContent

        public void removeContent()
        Removes all the content from the element
      • accept

        public void accept​(ElementVisitor visitor)
        Accept an visitor instance to allow the visitor to do some operations. Refer to visitor design pattern to get a better understanding.
        Parameters:
        visitor - an instance of DefaultElementVisitor
      • getComponentRoot

        public OdfElement getComponentRoot()
        Returns the component reference
      • markAsComponentRoot

        public void markAsComponentRoot​(boolean isRoot)
      • getComponent

        public Component getComponent()
      • setComponent

        public void setComponent​(Component component)
      • isComponentRoot

        public boolean isComponentRoot()
      • selfAndDescendantTextIgnoredAsComponent

        public boolean selfAndDescendantTextIgnoredAsComponent()
        Returns:
        true if the text should not count as for component path nor the element root itself. This might occur for nested paragraphs or ignored text element (e.g. text:note-citation).
      • ignoredComponent

        public void ignoredComponent​(boolean isIngoredComponent)
        Parameters:
        true - if the text should not count as for component path nor the element root itself. This might occur for nested paragraphs or ignored text element (e.g. text:note-citation). For instance called by a SAX Component parser, * * * * * * * see org.odftoolkit.odfdom.component.OdfFileSaxHandler
      • appendUsingWhitespaceHandling

        protected static void appendUsingWhitespaceHandling​(Node precedingNode,
                                                            OdfElement parent,
                                                            Node followingNode,
                                                            String newString)
        If the string is inserted into a text:p/text:h element and it will be inserted in the start/end all spaces are replaced by element(s). tabulator and linefeeds are being removed.

        If both the previous text node ends with a space and newString starts with a space, we would need to encode the single leading space as an element, otherwise it would be stripped. Same occurs for the next text node and an ending space. For Example: text text2 <== SAVE when starting ending a span as well with space element independent of preceding

      • split

        public OdfElement split​(int posStart)
        Splitting the element at the given position into two halves
        Parameters:
        posStart - The logical position of the first character (or other paragraph child component) that will be moved to the beginning of the new paragraph. Counting starts with 0.
        Returns:
        the new created second text container
      • receiveNode

        public Node receiveNode​(int textPosStart)
        Receives node from this text container element.
        Parameters:
        textPosStart - The start delimiter for the child
        Returns:
        the child node might be text or element
      • markText

        public void markText​(int textPosStart,
                             int textPosEnd,
                             org.json.JSONObject formatChanges)
        Parameters:
        textPosStart - the first text level component to be marked, start counting with 0
        textPosEnd - the last text level component to be marked, start counting with 0
        newSelection - the element that should embrace the text defined by the positions provided
      • countDescendantComponents

        public int countDescendantComponents()
        Counts the number of descendant components
      • countChildComponents

        public int countChildComponents​(Boolean hasTextComponents)
        Counts the number of child components
      • moveChildrenTo

        public void moveChildrenTo​(Element newParent)
      • insert

        public void insert​(String newString,
                           int textPosStart)
        Insert text to a certain position. The text will be appended to the previous position text, so the span of the previous character will be expanded
        Parameters:
        newString - string to be inserted
        position - text index of the new string
      • insert

        public void insert​(Node newNode,
                           int textPosStart)
      • delete

        public void delete​(int textPosStart,
                           int textPosEnd)
        Deletes text from this paragraph element.
        Parameters:
        textPosStart - Counting starts with 0, which is the first character of the paragraph.
        textPosEnd - The end delimiter for the deletion. To delete text to the end of the paragraph, as represent for the end of the paragraph Integer.MAX_VALUE can be used.
      • copyAttributes

        public static void copyAttributes​(OdfElement from,
                                          OdfElement to)
        Copy attributes from one element to another, existing attributes will be overwritten
      • getChildElement

        public Element getChildElement​(String uri,
                                       String localName)
        Returns:
        the first child element of a given parent
      • getChildElement

        public Element getChildElement​(String uri,
                                       String localName,
                                       int position)
        Returns:
        the child element of a given parent from a given position (starting with 0)
      • isIgnoredElement

        public static boolean isIgnoredElement​(Element element)
      • isIgnoredElement

        public static boolean isIgnoredElement​(String uri,
                                               String localName)
        ToDo: Move away to parser, as it is application logic not ODF relevant! Elements that blocks the creation of operations due to implementation issues
      • getNextSiblingElement

        public static OdfElement getNextSiblingElement​(Node node)
      • getPreviousSiblingElement

        public static OdfElement getPreviousSiblingElement​(Node node)
      • getFirstChildElement

        public OdfElement getFirstChildElement()
      • getLastChildElement

        public OdfElement getLastChildElement()
      • countPrecedingSiblingElements

        public int countPrecedingSiblingElements()
      • setRepetition

        public void setRepetition​(int repetition)
      • getTextContent

        public String getTextContent()
        Specified by:
        getTextContent in interface Node
        Overrides:
        getTextContent in class org.apache.xerces.dom.ParentNode
        Returns:
        the concatenated text contained by itself and all descendants (subtree). Does not take into account indented XML, as ODF whitespace handling require to neglect preceeding text content