List of usage examples for org.w3c.dom Node getPreviousSibling
public Node getPreviousSibling();
From source file:org.exist.dom.ElementImpl.java
/** * @see org.w3c.dom.Node#insertBefore(org.w3c.dom.Node, org.w3c.dom.Node) *//*from w ww .j ava2 s . co m*/ @Override public Node insertBefore(Node newChild, Node refChild) throws DOMException { if (refChild == null) { return appendChild(newChild); } if (!(refChild instanceof StoredNode)) { throw new DOMException(DOMException.WRONG_DOCUMENT_ERR, "Wrong node type"); } final NodeListImpl nl = new NodeListImpl(); nl.add(newChild); final TransactionManager transact = ownerDocument.getBrokerPool().getTransactionManager(); final Txn transaction = transact.beginTransaction(); DBBroker broker = null; try { broker = ownerDocument.getBrokerPool().get(null); insertBefore(transaction, nl, refChild); broker.storeXMLResource(transaction, (DocumentImpl) getOwnerDocument()); transact.commit(transaction); return refChild.getPreviousSibling(); } catch (final TransactionException e) { transact.abort(transaction); throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, e.getMessage()); } catch (final EXistException e) { transact.abort(transaction); LOG.warn("Exception while inserting node: " + e.getMessage(), e); } finally { if (broker != null) { try { transact.close(transaction); } finally { broker.release(); } } } return null; }
From source file:org.infoglue.cms.applications.structuretool.actions.ViewSiteNodePageComponentsAction.java
/** * This method moves the component up a step if possible within the same slot. *//*www . jav a2 s . co m*/ public String doMoveComponent() throws Exception { initialize(); String componentXML = getPageComponentsString(siteNodeId, this.masterLanguageVO.getId()); //logger.info("componentXML:" + componentXML); Document document = XMLHelper.readDocumentFromByteArray(componentXML.getBytes("UTF-8")); String componentXPath = "//component[@id=" + this.componentId + "]"; NodeList anl = org.apache.xpath.XPathAPI.selectNodeList(document.getDocumentElement(), componentXPath); if (anl.getLength() > 0) { Element component = (Element) anl.item(0); String name = component.getAttribute("name"); //logger.info(XMLHelper.serializeDom(component, new StringBuffer())); Node parentNode = component.getParentNode(); boolean hasChanged = false; if (this.direction.intValue() == 0) //Up { Node previousNode = component.getPreviousSibling(); while (previousNode != null && previousNode.getNodeType() != Node.ELEMENT_NODE) { previousNode = previousNode.getPreviousSibling(); //break; } Element element = ((Element) previousNode); while (element != null && !element.getAttribute("name").equalsIgnoreCase(name)) { previousNode = previousNode.getPreviousSibling(); while (previousNode != null && previousNode.getNodeType() != Node.ELEMENT_NODE) { previousNode = previousNode.getPreviousSibling(); //break; } element = ((Element) previousNode); } if (previousNode != null) { parentNode.removeChild(component); parentNode.insertBefore(component, previousNode); hasChanged = true; } } else if (this.direction.intValue() == 1) //Down { Node nextNode = component.getNextSibling(); while (nextNode != null && nextNode.getNodeType() != Node.ELEMENT_NODE) { nextNode = nextNode.getNextSibling(); break; } Element element = ((Element) nextNode); while (element != null && !element.getAttribute("name").equalsIgnoreCase(name)) { nextNode = nextNode.getNextSibling(); element = ((Element) nextNode); } if (nextNode != null) nextNode = nextNode.getNextSibling(); if (nextNode != null) { parentNode.removeChild(component); parentNode.insertBefore(component, nextNode); hasChanged = true; } else { parentNode.removeChild(component); parentNode.appendChild(component); hasChanged = true; } } if (hasChanged) { String modifiedXML = XMLHelper.serializeDom(document, new StringBuffer()).toString(); //logger.info("modifiedXML:" + modifiedXML); ContentVO contentVO = NodeDeliveryController .getNodeDeliveryController(siteNodeId, languageId, contentId) .getBoundContent(this.getInfoGluePrincipal(), siteNodeId, this.masterLanguageVO.getId(), true, "Meta information", DeliveryContext.getDeliveryContext()); ContentVersionVO contentVersionVO = ContentVersionController.getContentVersionController() .getLatestActiveContentVersionVO(contentVO.getId(), this.masterLanguageVO.getId()); ContentVersionController.getContentVersionController().updateAttributeValue( contentVersionVO.getContentVersionId(), "ComponentStructure", modifiedXML, this.getInfoGluePrincipal()); } } this.url = getComponentRendererUrl() + getComponentRendererAction() + "?siteNodeId=" + this.siteNodeId + "&languageId=" + this.languageId + "&contentId=" + this.contentId + "&focusElementId=" + this.componentId + "&showSimple=" + this.showSimple; //this.getResponse().sendRedirect(url); this.url = this.getResponse().encodeURL(url); this.getResponse().sendRedirect(url); return NONE; }
From source file:org.jasig.portal.layout.simple.SimpleLayout.java
@Override public String getPreviousSiblingId(String nodeId) throws PortalException { String prevSiblingId = null;/*from w w w .ja v a 2 s . c om*/ Element element = layout.getElementById(nodeId); if (element != null) { Node sibling = element.getPreviousSibling(); // Find the previous element node while (sibling != null && sibling.getNodeType() != Node.ELEMENT_NODE) { sibling = sibling.getPreviousSibling(); } if (sibling != null) { Element e = (Element) sibling; prevSiblingId = e.getAttribute("ID"); } } return prevSiblingId; }
From source file:org.kuali.rice.krad.demo.uif.library.fields.DemoFieldsActionAft.java
protected void testActionFieldButtons() throws Exception { WebElement exampleDiv = navigateToExample("Demo-ActionField-Example6"); List<WebElement> fields = exampleDiv.findElements(By.cssSelector("button.btn-primary")); assertEquals(7, fields.size());/*from ww w . j ava2 s.co m*/ String buttonFieldId = fields.get(0).getAttribute("id"); String imageBottomFieldId = fields.get(1).getAttribute("id"); String imageTopFieldId = fields.get(2).getAttribute("id"); String imageLeftFieldId = fields.get(3).getAttribute("id"); String imageRightFieldId = fields.get(4).getAttribute("id"); DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); XPath xPathFactory = XPathFactory.newInstance().newXPath(); Document document = builder.parse(IOUtils.toInputStream(driver.getPageSource())); assertIsVisible("#" + buttonFieldId); waitAndClickButtonByText(fields.get(0).getText()); assertTrue(driver.switchTo().alert().getText().contains("You clicked a button")); alertAccept(); assertElementPresent("#" + imageBottomFieldId + " span.topBottomSpan img[src*='searchicon.png']"); Node topFieldText = (Node) xPathFactory.evaluate( "//button[@id='" + imageBottomFieldId + "']/text()[contains(., 'Image BOTTOM')]", document, XPathConstants.NODE); Node topFieldTextNextSibling = topFieldText.getNextSibling(); if (!topFieldTextNextSibling.getNodeName().equals("span")) { fail("Image is not on the bottom of the text"); } assertElementPresent("#" + imageTopFieldId + " span.topBottomSpan img[src*='searchicon.png']"); Node bottomFieldText = (Node) xPathFactory.evaluate( "//button[@id='" + imageTopFieldId + "']/text()[contains(., 'Image TOP')]", document, XPathConstants.NODE); Node bottomFieldImgNextSibling = bottomFieldText.getPreviousSibling(); if (!bottomFieldImgNextSibling.getNodeName().contains("span")) { fail("Image is not on the top of the text"); } Node leftFieldImg = (Node) xPathFactory.evaluate("//button[@id='" + imageLeftFieldId + "']/img", document, XPathConstants.NODE); Node leftFieldImgNextSibling = leftFieldImg.getNextSibling(); if (!leftFieldImgNextSibling.getTextContent().contains("Image LEFT")) { fail("Image is not on the left of the text"); } Node rightFieldText = (Node) xPathFactory.evaluate( "//button[@id='" + imageRightFieldId + "']/text()[contains(., 'Image RIGHT')]", document, XPathConstants.NODE); Node rightFieldTextNextSibling = rightFieldText.getNextSibling(); if (!rightFieldTextNextSibling.getNodeName().equals("img")) { fail("Image is not on the right of the text"); } driver.findElement(By .xpath("//button[contains(text(),'Disabled Button') and @disabled]/preceding-sibling::button/img")); driver.findElement(By.xpath("//button/img[contains(@alt,'Image Only button')]")); driver.findElement(By.xpath("//button[contains(text(),'Disabled Button') and @disabled]")); }
From source file:org.kuali.test.handlers.htmltag.NotesAndAttachmentsTagHandler.java
private String getRowNumber(Element node) { String retval = ""; Node prev = node.getPreviousSibling(); while (prev != null) { if (Constants.HTML_TAG_TYPE_TH.equalsIgnoreCase(prev.getNodeName())) { try { String s = Utils.cleanDisplayText(prev); Integer.parseInt(s); retval = s;/*from ww w .ja v a 2 s . c om*/ break; } catch (NumberFormatException ex) { } } prev = prev.getPreviousSibling(); } return retval; }
From source file:org.kuali.test.utils.Utils.java
/** * * @param node//from w ww.j a va2 s . c om * @return */ public static Element getPreviousSiblingElement(Node node) { Element retval = null; Node sibling = node.getPreviousSibling(); while ((sibling != null) && !isElement(sibling)) { sibling = sibling.getPreviousSibling(); } if (isElement(sibling)) { retval = (Element) sibling; } return retval; }
From source file:org.metaeffekt.dcc.commons.ant.MergeXmlTaskTest.java
private Node getPreviousElementNode(Node node) { Node currentNode = node; while (currentNode.getPreviousSibling() != null && currentNode.getPreviousSibling().getNodeType() != Node.ELEMENT_NODE) { currentNode = currentNode.getPreviousSibling(); }/*from www . j a v a 2 s . co m*/ return currentNode.getPreviousSibling(); }
From source file:org.nuxeo.ecm.diff.service.impl.FieldDiffHelper.java
/** * Gets the node position.//from w w w . ja va 2s . c o m * * @param node the node * @return the node position */ private static int getNodePosition(Node node) { int nodePos = 0; Node previousSibling = node.getPreviousSibling(); while (previousSibling != null) { nodePos++; previousSibling = previousSibling.getPreviousSibling(); } return nodePos; }
From source file:org.nuxeo.theme.themes.ThemeParser.java
private static String getCommentAssociatedTo(Node node) { Node n = node; while (true) { n = n.getPreviousSibling(); if (n == null) { break; }//from ww w . java 2s . c om if (n.getNodeType() == Node.ELEMENT_NODE) { break; } if (n.getNodeType() == Node.COMMENT_NODE) { return n.getNodeValue().trim(); } } return null; }
From source file:org.smartfrog.avalanche.client.sf.apps.gt4.javawscore.utils.EditXML.java
/** * Adds a child node before the last child of the parent node. * @param parent//from w w w. ja v a 2s . co m * @param child */ public void addBeforeLastChild(Element parent, Element child) { Node lastChild = parent.getLastChild(); Node beforeLastChild = lastChild.getPreviousSibling(); if (child.getNodeName() == beforeLastChild.getNodeName()) { parent.replaceChild(child, beforeLastChild); } else { parent.insertBefore(child, lastChild); } }