List of usage examples for org.w3c.dom Element removeChild
public Node removeChild(Node oldChild) throws DOMException;
oldChild
from the list of children, and returns it. From source file:org.openmrs.module.xforms.aop.XformsConceptAdvisor.java
/** * Refreshes a coded concept in a given xforms select1 node. Where refreshing is simply adding * newly added answers and deleting those that have been removed from the coded concept. * //from ww w .jav a 2 s . c o m * @param conceptSelect1Element the concept's select1 node. * @param concept the coded concept. * @param doc the xforms document. * @param xform the xforms object. * @param xformsService the xforms service. */ private void refreshConceptWithId(Element conceptSelect1Element, Concept concept, Document doc, Xform xform, XformsService xformsService) { boolean xformModified = false; List<String> xformConceptAnswers = new ArrayList<String>(); Collection<ConceptAnswer> conceptAnswers = concept.getAnswers(); //Remove all deleted answers from the xform. NodeList elements = conceptSelect1Element.getElementsByTagName(XformBuilder.PREFIX_XFORMS + ":" + "item"); for (int index = 0; index < elements.getLength(); index++) { Element itemElement = (Element) elements.item(index); String conceptId = itemElement.getAttribute(XformBuilder.ATTRIBUTE_CONCEPT_ID); //If concept is not in the answers, it must have been deleted and so we need to remove it from the xform. if (!conceptAnswerInCollection(conceptAnswers, conceptId)) { conceptSelect1Element.removeChild(itemElement); xformModified = true; index--; } else xformConceptAnswers.add(conceptId); } //Add all new answers to the xform. for (ConceptAnswer conceptAnswer : conceptAnswers) { Concept answerConcept = conceptAnswer.getAnswerConcept(); if (answerConcept == null) continue; //Check if the xform already has this answer and add it if it does not exist. String conceptId = answerConcept.getConceptId().toString(); if (!xformConceptAnswers.contains(conceptId)) { addNewConceptAnswer(doc, answerConcept, conceptSelect1Element); xformModified = true; } } //Update name if changed. String newName = concept.getName().getName(); String oldName = Context.getService(XformsService.class).getConceptName(concept.getConceptId(), Context.getLocale().getLanguage()); if (!newName.equals(oldName)) { refreshConceptName(concept, newName, oldName, conceptSelect1Element); xformModified = true; } //Only save if there are changes to the xforms document. if (xformModified) { xform.setXformXml(XformsUtil.doc2String(doc)); xformsService.saveXform(xform); } }
From source file:com.alfaariss.oa.util.configuration.ConfigurationManager.java
/** * Remove a configuration section./* w ww . j av a2 s . c om*/ * @see IConfigurationManager#removeSection(org.w3c.dom.Element, java.lang.String, java.lang.String) */ public synchronized boolean removeSection(Element eRootSection, String sName, String sSectionID) throws ConfigurationException { if (sName == null) throw new IllegalArgumentException("Suplied name is empty"); if (sSectionID == null) throw new IllegalArgumentException("Suplied section id is empty"); boolean bRet = false; try { if (eRootSection == null) eRootSection = _oDomDocument.getDocumentElement(); Node nSection = this.getSubSectionByID(eRootSection, sName, sSectionID); if (nSection == null) _logger.debug("Section not found: " + sName); else { //remove section eRootSection.removeChild(nSection); bRet = true; } } catch (DOMException e) { StringBuffer sb = new StringBuffer("Error removing section: "); sb.append(sName).append(", id=").append(sSectionID); _logger.error(sb.toString(), e); throw new ConfigurationException(SystemErrors.ERROR_CONFIG_DELETE); } return bRet; }
From source file:eu.europa.ec.markt.dss.signature.xades.XAdESProfileT.java
@SuppressWarnings("unchecked") protected void extendSignatureTag(Element signatureEl, Document originalData, SignatureFormat signatureFormat) { try {//ww w . j av a 2 s . com Element qualifyingProperties = XMLUtils.getElement(signatureEl, "./ds:Object/xades:QualifyingProperties"); Element unsignedPropertiesNode = XMLUtils.getElement(qualifyingProperties, "./xades:UnsignedProperties"); UnsignedPropertiesType unsignedPropertiesType = null; if (unsignedPropertiesNode != null) { unsignedPropertiesType = ((JAXBElement<UnsignedPropertiesType>) unmarshaller .unmarshal(unsignedPropertiesNode)).getValue(); } else { unsignedPropertiesType = xadesObjectFactory.createUnsignedPropertiesType(); } extendSignatureTag(signatureEl, unsignedPropertiesType, signatureFormat); if (unsignedPropertiesNode != null) { qualifyingProperties.removeChild(unsignedPropertiesNode); } marshaller.marshal(xadesObjectFactory.createUnsignedProperties(unsignedPropertiesType), qualifyingProperties); } catch (XPathExpressionException e) { throw new RuntimeException(e); } catch (JAXBException e) { throw new RuntimeException("JAXB error: " + e.getMessage(), e); } catch (IOException e) { throw new RuntimeException(e); } }
From source file:com.autentia.mvn.plugin.changes.BugzillaChangesMojo.java
/** * Addapts bugzilla XML document for transformations * /*from w w w . j av a 2s .co m*/ * @param docBugzilla */ private void cleanBugzillaDocument(final Document docBugzilla) { // quitamos el DTD final Node docType = docBugzilla.getDoctype(); docBugzilla.removeChild(docType); // ponemos el ttulo final Element title = docBugzilla.createElement(ELEMENT_TITLE); title.appendChild(docBugzilla.createTextNode(this.project.getName())); docBugzilla.getDocumentElement().appendChild(title); // ponemos los atributos de version para la ordenacin final NodeList target_milestones = docBugzilla.getElementsByTagName(ELEMENT_TARGET_MILESTONE); for (int i = 0; i < target_milestones.getLength(); i++) { final Element target_milestone = (Element) target_milestones.item(i); final String version = target_milestone.getTextContent(); final String[] versions = version.split("\\."); // solo tenemos en cuenta las dos primeras // (ej. para version="1.23" tenemos la version1="1" y version2="23"; // y para version="1.23.3" se tiene lo mismo) String version1 = ""; if (versions.length > 0) { version1 = versions[0]; } String version2 = ""; if (versions.length >= 2) { version2 = versions[1]; } target_milestone.setAttribute(ATTRIBUTE_VERSION1, version1); target_milestone.setAttribute(ATTRIBUTE_VERSION2, version2); } // si hay que ajustar los desarrolladores lo procesamos if (this.fitDevelopers) { final NodeList assigned_tos = docBugzilla.getElementsByTagName(ELEMENT_ASSIGNED_TO); for (int i = 0; i < assigned_tos.getLength(); i++) { final Element assigned_to = (Element) assigned_tos.item(i); String developer = assigned_to.getTextContent(); final int index = developer.indexOf("@"); if (index != -1) { developer = developer.substring(0, index); } // quitamos el texto final NodeList childs = assigned_to.getChildNodes(); for (int j = 0; j < childs.getLength(); j++) { final Node child = childs.item(j); assigned_to.removeChild(child); // disminuimos j debido a que tambin se quita del nodelist j--; } assigned_to.appendChild(docBugzilla.createTextNode(developer)); } } // eliminamos los nodos que no son necesarios final String[] nodes2Clean = { "creation_ts", "reporter_accessible", "cclist_accessible", "classification_id", "classification", "product", "component", "version", "rep_platform", "op_sys", "bug_status", "resolution", "priority", "everconfirmed", "estimated_time", "remaining_time", "actual_time", "who", "thetext" }; for (final String node2clean : nodes2Clean) { this.removeNodes(docBugzilla.getElementsByTagName(node2clean)); } }
From source file:net.sf.jclal.experiment.ExperimentBuilder.java
private int expandElementsIterateAtributes(Element element, int[] configurationSchema) { NamedNodeMap attributes = element.getAttributes(); for (int i = 0; i < attributes.getLength(); i++) { Node attribute = attributes.item(i); if (attribute.getNodeName().equals("multi")) { NodeList list = element.getElementsByTagName(element.getNodeName()); for (int j = 0; j < configurationSchema.length; j++) { if (configurationSchema[j] != -1) { element.getParentNode().replaceChild(list.item(configurationSchema[j]), element); configurationSchema[j] = -1; break; }/*from w w w.j a v a 2 s .co m*/ } list = element.getChildNodes(); for (int j = 0; j < list.getLength(); j++) { if (list.item(j).getNodeName().equals(attribute.getNodeName())) { element.removeChild(list.item(j)); } } return 1; } } return 0; }
From source file:net.sf.jclal.experiment.ExperimentBuilder.java
private int expandAttributesIterateAtributes(Element element, int[] configurationSchema) { NamedNodeMap attributes = element.getAttributes(); for (int i = 0; i < attributes.getLength(); i++) { Node attribute = attributes.item(i); if (attribute.getNodeValue().equals("multi")) { NodeList list = element.getElementsByTagName(attribute.getNodeName()); for (int j = 0; j < configurationSchema.length; j++) { if (configurationSchema[j] != -1) { attribute.setNodeValue(list.item(configurationSchema[j]).getFirstChild().getNodeValue()); configurationSchema[j] = -1; break; }/*from w w w . ja v a 2s .co m*/ } list = element.getChildNodes(); for (int j = 0; j < list.getLength(); j++) { if (list.item(j).getNodeName().equals(attribute.getNodeName())) { element.removeChild(list.item(j)); } } return 1; } } return 0; }
From source file:org.openmrs.module.xforms.aop.XformsLocationAdvisor.java
/** * Refreshes a location in a given xforms select1 node. * /*ww w . j ava2 s . co m*/ * @param operation the refresh operation. * @param locationSelect1Element the location select1 node. * @param location the location. * @param oldName the location name before editing. * @param doc the xforms document. * @param xform the xform object. * @param xformsService the xforms service. * @throws Exception */ private void refreshLocationWithId(RefreshOperation operation, Element locationSelect1Element, Location location, String oldName, Document doc, Xform xform, XformsService xformsService) throws Exception { String sLocationId = location.getLocationId().toString(); if (operation == RefreshOperation.DELETE || operation == RefreshOperation.EDIT) { //Get all xf:item nodes. NodeList elements = locationSelect1Element .getElementsByTagName(XformBuilder.PREFIX_XFORMS + ":" + "item"); boolean locationFound = false; //Look for an item node having an id attribute equal to the locationId. for (int index = 0; index < elements.getLength(); index++) { Element itemElement = (Element) elements.item(index); if (!sLocationId.equals(itemElement.getAttribute(XformBuilder.ATTRIBUTE_ID))) continue; //Not the location we are looking for. //If the location has been deleted, then remove their item node from the xforms document. if (operation == RefreshOperation.DELETE) { locationSelect1Element.removeChild(itemElement); } else { //New name for the location after editing. String newName = XformBuilder.getLocationName(location); //If name has not changed, then just do nothing. if (newName.equals(oldName)) return; //If the location name has been edited, then change the xf:label node text. NodeList labels = itemElement.getElementsByTagName(XformBuilder.PREFIX_XFORMS + ":" + "label"); //If the existing xforms label is not the same as the previous location's name, then //do not change it, possibly the location wants the xforms value not to match the location's name. Element labelElement = (Element) labels.item(0); if (!oldName.equals(labelElement.getTextContent())) return; labelElement.setTextContent(newName); } locationFound = true; break; } //select1 node does not have the location to delete or edit. if (!locationFound) { if (operation == RefreshOperation.DELETE) return; addNewLocationNode(doc, locationSelect1Element, location); } } else { //Older versions of openmrs call AOP advisors more than once hence resulting into duplicates //if this check is not performed. if (locationExists(locationSelect1Element, sLocationId)) return; //Add new location addNewLocationNode(doc, locationSelect1Element, location); } xform.setXformXml(XformsUtil.doc2String(doc)); xformsService.saveXform(xform); }
From source file:org.openmrs.module.xforms.aop.XformsProviderAdvisor.java
/** * Refreshes a provider in a given xforms select1 node. * // w w w .j a va 2s .co m * @param operation the refresh operation. * @param providerSelect1Element the provider select1 node. * @param user the provider. * @param oldName the provider name before editing. * @param doc the xforms document. * @param xform the xform object. * @param xformsService the xforms service. * @throws Exception */ private void refreshProviderWithId(RefreshOperation operation, Element providerSelect1Element, User user, String oldName, Document doc, Xform xform, XformsService xformsService) throws Exception { Integer personId = XformsUtil.getPersonId(user); String sPersonId = personId.toString(); if (operation == RefreshOperation.DELETE || operation == RefreshOperation.EDIT) { //Get all xf:item nodes. NodeList elements = providerSelect1Element .getElementsByTagName(XformBuilder.PREFIX_XFORMS + ":" + "item"); boolean providerFound = false; //Look for an item node having an id attribute equal to the userId. for (int index = 0; index < elements.getLength(); index++) { Element itemElement = (Element) elements.item(index); if (!sPersonId.equals(itemElement.getAttribute(XformBuilder.ATTRIBUTE_ID))) continue; //Not the provider we are looking for. //If the user has been deleted, then remove their item node from the xforms document. if (operation == RefreshOperation.DELETE) { providerSelect1Element.removeChild(itemElement); } else { //New name for the provider after editing. String newName = XformBuilder.getProviderName(user, personId); //If name has not changed, then just do nothing. if (newName.equals(oldName)) return; //If the user name has been edited, then change the xf:label node text. NodeList labels = itemElement.getElementsByTagName(XformBuilder.PREFIX_XFORMS + ":" + "label"); //If the existing xforms label is not the same as the previous user's name, then //do not change it, possibly the user wants the xforms value not to match the user's name. Element labelElement = (Element) labels.item(0); if (!oldName.equals(labelElement.getTextContent())) return; labelElement.setTextContent(newName); } providerFound = true; break; } //select1 node does not have the provider to delete or edit. if (!providerFound) { if (operation == RefreshOperation.DELETE) return; //This must be a person who has just got a provider role which he or she did not have before. addNewProviderNode(doc, providerSelect1Element, user, personId); } } else { //Older versions of openmrs call AOP advisors more than once hence resulting into duplicates //if this check is not performed. if (providerExists(providerSelect1Element, sPersonId)) return; //Add new provider addNewProviderNode(doc, providerSelect1Element, user, personId); } xform.setXformXml(XformsUtil.doc2String(doc)); xformsService.saveXform(xform); }
From source file:com.bstek.dorado.view.config.XmlDocumentPreprocessor.java
@SuppressWarnings("unchecked") private void postProcessNodeReplacement(Element element) { Document ownerDocument = element.getOwnerDocument(); Node child = element.getFirstChild(); while (child != null) { Node nextChild = child.getNextSibling(); if (child instanceof Element) { if (child.getUserData("dorado.delete") != null) { List<Element> replaceContent = (List<Element>) child.getUserData("dorado.replace"); if (replaceContent != null) { for (Element el : replaceContent) { Element clonedElement = (Element) ownerDocument.importNode(el, true); element.insertBefore(clonedElement, child); }/*from w ww . j a va 2 s . c om*/ child.setUserData("dorado.replace", null, null); } element.removeChild(child); child.setUserData("dorado.delete", null, null); } } child = nextChild; } }