Example usage for org.w3c.dom Element getNextSibling

List of usage examples for org.w3c.dom Element getNextSibling

Introduction

In this page you can find the example usage for org.w3c.dom Element getNextSibling.

Prototype

public Node getNextSibling();

Source Link

Document

The node immediately following this node.

Usage

From source file:org.jasig.portal.layout.dlm.PositionManager.java

/**
   This method compares the children by id in the order list with
   the order in the compViewParent's ui visible children and returns true
   if the ordering differs indicating that the positioning if needed.
 *//*from   w ww .  ja  v a 2s  . c  om*/
static boolean hasAffectOnCVP(List<NodeInfo> order, Element compViewParent) {
    if (order.size() == 0)
        return false;

    int idx = 0;
    Element child = (Element) compViewParent.getFirstChild();
    NodeInfo ni = (NodeInfo) order.get(idx);

    if (child == null && ni != null) // most likely nodes to be pulled in
        return true;

    while (child != null) {
        if (child.getAttribute("hidden").equals("false")
                && (!child.getAttribute("chanID").equals("") || child.getAttribute("type").equals("regular"))) {
            if (ni.id.equals(child.getAttribute(Constants.ATT_ID))) {
                if (idx >= order.size() - 1) // at end of order list
                    return false;

                ni = (NodeInfo) order.get(++idx);
            } else // if not equal then return true
                return true;
        }
        child = (Element) child.getNextSibling();
    }
    if (idx < order.size())
        return true; // represents nodes to be pulled in
    return false;
}

From source file:org.jasig.portal.layout.dlm.PositionManager.java

/**
   Return true if the passed in node or any of its up-stream (higher index
   siblings have moveAllowed="false"./* ww w  .  j a v a  2s. com*/
 */
private static boolean isNotReparentable(NodeInfo ni) {
    if (ni.node.getAttribute(Constants.ATT_MOVE_ALLOWED).equals("false"))
        return true;

    Precedence nodePrec = ni.precedence;
    Element node = (Element) ni.node.getNextSibling();

    while (node != null) {
        if (node.getAttribute(Constants.ATT_MOVE_ALLOWED).equals("false")) {
            Precedence p = Precedence.newInstance(node.getAttribute(Constants.ATT_FRAGMENT));
            if (nodePrec.isEqualTo(p))
                return true;
        }
        node = (Element) node.getNextSibling();
    }
    return false;
}

From source file:org.jasig.portal.layout.dlm.PositionManager.java

/**
   This method assembles in the passed in order object a list of NodeInfo
   objects ordered first by those specified in the position set and whose
   nodes still exist in the composite view and then by any remaining
   children in the compViewParent.//www  . j a  v  a  2  s. c  o  m
 */
static void applyOrdering(List<NodeInfo> order, Element compViewParent, Element positionSet) {
    // first pull out all visible channel or visible folder children and
    // put their id's in a list of available children and record their
    // relative order in the CVP.

    final Map<String, NodeInfo> available = new LinkedHashMap<String, NodeInfo>();

    Element child = (Element) compViewParent.getFirstChild();
    Element next = null;
    int indexInCVP = 0;

    while (child != null) {
        next = (Element) child.getNextSibling();

        if (child.getAttribute("hidden").equals("false")
                && (!child.getAttribute("chanID").equals("") || child.getAttribute("type").equals("regular"))) {
            final NodeInfo nodeInfo = new NodeInfo(child, indexInCVP++);

            final NodeInfo prevNode = available.put(nodeInfo.id, nodeInfo);
            if (prevNode != null) {
                throw new IllegalStateException("Infinite loop detected in layout. Triggered by " + nodeInfo.id
                        + " with already visited node ids: " + available.keySet());
            }
        }
        child = next;
    }

    // now fill the order list using id's from the position set if nodes
    // having those ids exist in the composite view. Otherwise discard
    // that position directive. As they are added to the list remove them
    // from the available nodes in the parent.

    Document CV = compViewParent.getOwnerDocument();
    Element directive = (Element) positionSet.getFirstChild();

    while (directive != null) {
        next = (Element) directive.getNextSibling();

        // id of child to move is in the name attrib on the position nodes
        String id = directive.getAttribute("name");
        child = CV.getElementById(id);

        if (child != null) {
            // look for the NodeInfo for this node in the available
            // nodes and if found use that one. Otherwise use a new that
            // does not include an index in the CVP parent. In either case
            // indicate the position directive responsible for placing this
            // NodeInfo object in the list.

            final String childId = child.getAttribute(Constants.ATT_ID);
            NodeInfo ni = available.remove(childId);
            if (ni == null) {
                ni = new NodeInfo(child);
            }

            ni.positionDirective = directive;
            order.add(ni);
        }
        directive = next;
    }

    // now append any remaining ids from the available list maintaining
    // the order that they have there.

    order.addAll(available.values());
}

From source file:org.jasig.portal.layout.simple.SimpleLayout.java

@Override
public String getNextSiblingId(String nodeId) throws PortalException {
    String nextSiblingId = null;//w w w . j a  v a2  s. c  om
    Element element = layout.getElementById(nodeId);
    if (element != null) {
        Node sibling = element.getNextSibling();
        // Find the next element node
        while (sibling != null && sibling.getNodeType() != Node.ELEMENT_NODE) {
            sibling = sibling.getNextSibling();
        }
        if (sibling != null) {
            Element e = (Element) sibling;
            nextSiblingId = e.getAttribute("ID");
        }
    }
    return nextSiblingId;
}

From source file:org.openmrs.projectbuendia.webservices.rest.XformResource.java

/**
 * Converts a vanilla Xform into one that ODK Collect is happy to work with.
 * This requires:/*  ww  w. j a v  a2 s. c om*/
 * <ul>
 * <li>Changing the namespace of the the root element to http://www.w3.org/1999/xhtml
 * <li>Wrapping the model element in an HTML head element, with a title child element
 * <li>Wrapping remaining elements in an HTML body element
 * </ul>
 */
static String convertToOdkCollect(String xml, String title) throws IOException, SAXException {
    // Change the namespace of the root element. I haven't figured out a way
    // to do
    // this within a document; removing the root element from the document
    // seems
    // to do odd things... so instead, we import it into a new document.
    Document oldDoc = XmlUtil.parse(xml);
    Document doc = XmlUtil.getDocumentBuilder().newDocument();
    Element root = (Element) doc.importNode(oldDoc.getDocumentElement(), true);
    root = (Element) doc.renameNode(root, HTML_NAMESPACE, "h:form");
    doc.appendChild(root);

    // Prepare the new wrapper elements
    Element head = doc.createElementNS(HTML_NAMESPACE, "h:head");
    Element titleElement = XmlUtil.appendElementNS(head, HTML_NAMESPACE, "h:title");
    titleElement.setTextContent(title);
    Element body = doc.createElementNS(HTML_NAMESPACE, "h:body");

    // Find the model element to go in the head, and all its following
    // siblings to go in the body.
    // We do this before moving any elements, for the sake of sanity.
    Element model = getElementOrThrowNS(root, XFORMS_NAMESPACE, "model");
    List<Node> nodesAfterModel = new ArrayList<>();
    Node nextSibling = model.getNextSibling();
    while (nextSibling != null) {
        nodesAfterModel.add(nextSibling);
        nextSibling = nextSibling.getNextSibling();
    }

    // Now we're done with the preparation, we can move everything.
    head.appendChild(model);
    for (Node node : nodesAfterModel) {
        body.appendChild(node);
    }

    // Having removed the model and everything after it, we can now just
    // append the head and body to the document element...
    root.appendChild(head);
    root.appendChild(body);

    return XformsUtil.doc2String(doc);
}

From source file:org.seasar.uruma.eclipath.classpath.EclipseClasspath.java

public void removeClasspathEntryElement(Element entry) {
    Node nextSibling = entry.getNextSibling();
    Node removed = classpathElement.removeChild(entry);
    if (removed != null) {
        if (nextSibling != null && isWhitespaceText(nextSibling)) {
            classpathElement.removeChild(nextSibling);
        }//from  w w  w  .  j  av a 2 s .co  m
        Logger.info("Library removed. : " + entry.getAttribute(ATTR_PATH));
        isChanged = true;
    }
}

From source file:org.xwiki.officeimporter.internal.filter.ImageFilter.java

/**
 * {@inheritDoc}/*from   www . j a  v a2s.  c  o  m*/
 */
public void filter(Document htmlDocument, Map<String, String> cleaningParams) {
    String targetDocument = cleaningParams.get("targetDocument");
    DocumentReference targetDocumentReference = null;

    List<Element> images = filterDescendants(htmlDocument.getDocumentElement(), new String[] { TAG_IMG });
    for (Element image : images) {
        if (targetDocumentReference == null && !StringUtils.isBlank(targetDocument)) {
            targetDocumentReference = documentStringReferenceResolver.resolve(targetDocument);
        }
        String src = image.getAttribute(ATTRIBUTE_SRC);
        if (!StringUtils.isBlank(src) && targetDocumentReference != null) {
            // OpenOffice 3.2 server generates relative image paths, extract image name.
            int separator = src.lastIndexOf("/");
            if (-1 != separator) {
                src = src.substring(separator + 1);
            }
            try {
                // We have to decode the image file name in case it contains URL special characters.
                src = URLDecoder.decode(src, "UTF-8");
            } catch (UnsupportedEncodingException e) {
                // This should never happen.
            }

            // Set image source attribute relative to the reference document.
            AttachmentReference attachmentReference = new AttachmentReference(src, targetDocumentReference);
            image.setAttribute(ATTRIBUTE_SRC,
                    documentAccessBridge.getAttachmentURL(attachmentReference, false));

            // The 'align' attribute of images creates a lot of problems. First, OO server has a problem with
            // center aligning images (it aligns them to left). Next, OO server uses <br clear"xxx"> for
            // avoiding content wrapping around images which is not valid xhtml. There for, to be consistent and
            // simple we will remove the 'align' attribute of all the images so that they are all left aligned.
            image.removeAttribute(ATTRIBUTE_ALIGN);
        } else if (src.startsWith("file://")) {
            src = "Missing.png";
            image.setAttribute(ATTRIBUTE_SRC, src);
            image.setAttribute(ATTRIBUTE_ALT, src);
        }
        ResourceReference imageReference = new ResourceReference(src, ResourceType.ATTACHMENT);
        imageReference.setTyped(false);
        Comment beforeComment = htmlDocument
                .createComment("startimage:" + this.xhtmlMarkerSerializer.serialize(imageReference));
        Comment afterComment = htmlDocument.createComment("stopimage");
        image.getParentNode().insertBefore(beforeComment, image);
        image.getParentNode().insertBefore(afterComment, image.getNextSibling());
    }
}

From source file:ru.runa.wf.web.FormPresentationUtils.java

private static void handleErrors(Map<String, String> errors, String inputName, PageContext pageContext,
        Document document, Element node) {
    if (errors.containsKey(inputName)) {
        String errorText = getErrorText(pageContext, errors, inputName);
        if ("file".equalsIgnoreCase(node.getAttribute(TYPE_ATTR)) && WebResources.isAjaxFileInputEnabled()) {
            try {
                node = (Element) ((Element) ((Element) node.getParentNode()).getParentNode()).getParentNode();
            } catch (Exception e) {
                log.error("Unexpected file input format", e);
            }//w w w .java2  s. c om
        }
        if (WebResources.useImagesForValidationErrors()) {
            Element errorImg = document.createElement("img");
            errorImg.setAttribute("title", errorText);
            errorImg.setAttribute("src",
                    Commons.getUrl("/images/error.gif", pageContext, PortletUrlType.Resource));
            Node parent = node.getParentNode();
            parent.insertBefore(errorImg, node.getNextSibling());
        } else {
            node.setAttribute("title", errorText);
            if ("select".equalsIgnoreCase(node.getTagName())) {
                node = wrapSelectToErrorContainer(document, node, inputName, false);
            }
            addClassAttribute(node, Resources.CLASS_INVALID);
        }
        // avoiding multiple error labels
        errors.remove(inputName);
    }
}