Package com.volantis.mcs.dom

Examples of com.volantis.mcs.dom.Node


        }

        if (removeFirstCard) {
            // The first card is essentially empty so remove it.
            Element root = buffer.getRoot();
            Node node = root.getHead();
            if (node != null && node instanceof Element) {
                Element card = (Element)node;
                if (logger.isDebugEnabled()) {
                    logger.debug("Removing card " + card);
                }
View Full Code Here


        tableElement.setObject(null);

        // If the table contains a caption (which will be a BLOCH element as the
        // first child of the table) move the caption either above or below
        // the table depending on its caption-side style property.
        Node firstNodeChild = tableElement.getHead();
        if (firstNodeChild instanceof Element) {
            Element firstChild = (Element) firstNodeChild;
            if (firstChild != null && WMLConstants.BLOCH_ELEMENT.equals(
                    firstChild.getName())) {
                StyleValue captionSide = firstChild.getStyles().
View Full Code Here

     */
    public void transform(Element element) {

        String href = element.getAttributeValue(HREF);

        Node child = element.getHead();

        while (child != null) {

            if (child instanceof Element) {
                Element childElement = (Element)child;

                childElement.setAttribute(HREF, href);
            }

            child = child.getNext();

        }

        element.removeAttribute(HREF);
    }
View Full Code Here

                // (see VBM:2004102003) but this visitor is so fragile I am
                // loath to change it. So, in this case we just check for the
                // trivial case where all the child elements are redundant and
                // remove them.
                boolean allChildrenRedundant = true;
                Node childNode = element.getHead();
                while (childNode != null && allChildrenRedundant) {
                    if (childNode instanceof Element) {
                        Element childElement = (Element) childNode;
                        if (elementName.equals(childElement.getName())) {
                            // Check to see if all the child attributes are
                            // present and the same in the parent.
                            Attribute attribute = childElement.getAttributes();
                            while (attribute != null && allChildrenRedundant) {
                                String value = element.getAttributeValue(
                                        attribute.getName());
                                if (!attribute.getValue().equals(value)) {
                                    // child's attributes are different
                                    allChildrenRedundant = false;
                                }
                                attribute = attribute.getNext();
                            }
                        } else {
                            // element names are different
                            allChildrenRedundant = false;
                        }
                    }
                    childNode = childNode.getNext();
                }

                if (allChildrenRedundant) {
                    // remove all the children *carefully*
                    childNode = element.getHead();
                    while (childNode != null) {
                        // Remember the next node in case we disturb it.
                        Node next = childNode.getNext();
                        // Remove the element.
                        if (childNode instanceof Element) {
                            removeElement((Element) childNode);
                        }
                        // Move to the next node.
                        childNode = next;
                    }
                }

                // close the tracker.
                tracker.closed(elementName);
                element.forEachChild(this);

            } else {
                Node sibling = element.getNext();

                processElementToBeRemoved(element);

                // Visit siblings to the right.
                while (sibling != null) {
                    sibling.accept(this);
                    sibling = sibling.getNext();
                }
                // continue current traversal.
            }
        } else {
            // Track this element (opened).
View Full Code Here

        if (logger.isDebugEnabled()) {
            logger.debug("Processing anti-element: " + element);
        }

        Node sibling = element.getNext();

        Iterator stylisticElements = styleCfg.getCounterpartElementNames(
                antiElementName);
        boolean promoted = false;
        while (stylisticElements.hasNext()) {
            String stylisticElementName = (String) stylisticElements.next();
            if (tracker.isOpen(stylisticElementName)) {
                // Recursively promote the element until it reaches
                // the same level as its counterpart element.
                promoteAntiElementRecursively(
                        element, stylisticElementName, tracker);
                promoted = true;
            }
        }
        if (promoted) {
            // Get the (possibly) new sibling of the promoted element.
            sibling = element.getNext();
            tracker.closed(antiElementName);
        }

        // Visited my children before removing the anti-element.
        processElementToBeRemoved(element);

        // Visit siblings to the right.
        while (sibling != null) {
            sibling.accept(this);
            sibling = sibling.getNext();
        }
    }
View Full Code Here

     */
    private void debugNode(Node node, String message) {
        if (logger.isDebugEnabled()) {

            // Calculate the path to this element for debugging.
            Node parent = node;
            Stack stack = new ArrayListStack();
            do {
                stack.push(parent);
                parent = parent.getParent();
            } while (parent != null);

            // Remove the fake parent node if there is one.
            Node top = (Node) stack.peek();
            if (top instanceof Element && ((Element) top).getName() == null) {
                stack.pop();
            }

            StringBuffer path = new StringBuffer();
            while (!stack.isEmpty()) {
                Node pathNode = (Node) stack.pop();

                if (pathNode instanceof Element) {
                    final String name = ((Element) pathNode).getName();
                    path.append(name);
                } else {
                    path.append("(text)");
                }

                // Count the next and previous nodes
                int nextCount = 0;
                Node next = pathNode.getNext();
                while (next != null) {
                    nextCount++;
                    next = next.getNext();
                }
                int previousCount = 0;
                Node previous = pathNode.getPrevious();
                while (previous != null) {
                    previousCount++;
                    previous = previous.getPrevious();
                }
                int position = previousCount + 1;
                int total = position + nextCount;
                path.append("[").append(position).append(":").append(total)
                        .append("]");
View Full Code Here

    private void processElementToBeRemoved(Element element) {

        if (logger.isDebugEnabled()) {
            logger.debug("Removing element: " + element);
        }
        Node head = element.getHead();
        Node tail = element.getTail();

        // Remove the element after storing the elements head and tail.
        removeElement(element);

        if (head != null) {
            // We have at least one child node.
            Node next = head;
            boolean processedTail = false;
            while ((next != null) && !processedTail) {
                next.accept(this);
                processedTail = next == tail;
                next = next.getNext();
            }
        }
        if (logger.isDebugEnabled()) {
            logger.debug("Element removed: " + element);
        }
View Full Code Here

                if ((wrapNode)) {
                    // Processing a text node so create a new clone of the
                    // stylistic element and add the text as a child of this
                    // new element. Update the tree so that the new element
                    // 'replaces' the text node.
                    Node leftSibling = x.getPrevious();
                    Element parent = x.getParent();

                    Element newElement = domFactory.createElement();
                    newElement.copy(elementToPushDown);
View Full Code Here

     * </pre>
     *
     * @param element the element to remove.
     */
    private void removeElement(Element element) {
        Node leftSibling = element.getPrevious();
        if (leftSibling != null) {
            element.insertChildrenAfter(leftSibling);
        } else {
            element.addChildrenToHead(element.getParent());
        }
View Full Code Here

     *
     * @param element the element who's children are to be visited.
     */
    private void forEachChildAllowingModification(Element element) {

        Node node = element.getHead();
        while (node != null) {
            node.accept(this);
            node = node.getNext();
        }
    }
View Full Code Here

TOP

Related Classes of com.volantis.mcs.dom.Node

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.