List of usage examples for org.w3c.dom Element getPreviousSibling
public Node getPreviousSibling();
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. *///w ww . java2 s . c o 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.infoglue.common.contenttypeeditor.actions.ViewContentTypeDefinitionAction.java
/** * This method moves an content type assetKey up one step. *//*from w w w.j a v a2s.com*/ public String doMoveAssetKeyUp() throws Exception { this.initialize(getContentTypeDefinitionId()); try { Document document = createDocumentFromDefinition(); String attributesXPath = "/xs:schema/xs:simpleType[@name = '" + ContentTypeDefinitionController.ASSET_KEYS + "']/xs:restriction/xs:enumeration[@value='" + this.assetKey + "']"; NodeList anl = XPathAPI.selectNodeList(document.getDocumentElement(), attributesXPath); if (anl != null && anl.getLength() > 0) { Element element = (Element) anl.item(0); Node parentElement = element.getParentNode(); Node previuosSibling = element.getPreviousSibling(); if (previuosSibling != null) { parentElement.removeChild(element); parentElement.insertBefore(element, previuosSibling); } } saveUpdatedDefinition(document); } catch (Exception e) { e.printStackTrace(); } this.initialize(getContentTypeDefinitionId()); return UPDATED; }
From source file:org.jasig.portal.layout.simple.SimpleLayout.java
@Override public String getPreviousSiblingId(String nodeId) throws PortalException { String prevSiblingId = null;/*from ww w .jav a2s .c o m*/ 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.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 w w w.j av a 2 s. c o m*/ break; } catch (NumberFormatException ex) { } } prev = prev.getPreviousSibling(); } return retval; }