List of usage examples for org.w3c.dom Element getOwnerDocument
public Document getOwnerDocument();
Document
object associated with this node. From source file:jef.tools.XMLUtils.java
/** * ?????/*from w w w.j ava 2 s . c om*/ * * @param node * ???? * @param newName * ?? * @return ????DOMElement */ public static Element changeNodeName(Element node, String newName) { Document doc = node.getOwnerDocument(); Element newEle = doc.createElement(newName); Node parent = node.getParentNode(); parent.removeChild(node); parent.appendChild(newEle); for (Node child : toArray(node.getChildNodes())) { node.removeChild(child); newEle.appendChild(child); } return newEle; }
From source file:net.bpelunit.framework.SpecificationLoader.java
private Element copyAsRootWithNamespaces(XmlObject xmlData) throws SpecificationException { final Element rawDataRoot = BPELUnitUtil.generateDummyElementNode(); final Document rawDataDoc = rawDataRoot.getOwnerDocument(); final XmlCursor dataCursor = xmlData.newCursor(); if (dataCursor.toFirstChild()) { do {//from w ww . j ava 2 s . c o m // Skip comments if (dataCursor.isComment()) { continue; } if (dataCursor.isContainer()) { // Import elements, including their namespace nodes final Node original = dataCursor.getDomNode(); final Node imported = rawDataDoc.importNode(original, true); rawDataRoot.appendChild(imported); } } while (dataCursor.toNextSibling()); } dataCursor.dispose(); return rawDataRoot; }
From source file:de.qucosa.webapi.v1.DocumentResource.java
private FileUpdateOperation updateFileNodeWith(Element target, Element update) throws FedoraClientException, IOException, XPathExpressionException { FileUpdateOperation fupo = new FileUpdateOperation(); NodeList updateNodes = update.getChildNodes(); for (int i = 0; i < updateNodes.getLength(); i++) { if (updateNodes.item(i).getNodeType() == Node.ELEMENT_NODE) { Element updateField = (Element) updateNodes.item(i); String updateFieldLocalName = updateField.getLocalName(); Element targetElement = (Element) target.getElementsByTagName(updateFieldLocalName).item(0); if (targetElement == null) { targetElement = target.getOwnerDocument().createElement(updateFieldLocalName); target.appendChild(targetElement); targetElement.appendChild(target.getOwnerDocument().createTextNode("")); }//from w w w .ja va 2 s.c o m String oldVal = targetElement.getTextContent(); String newVal = updateField.getTextContent(); if (!oldVal.equals(newVal)) { switch (updateFieldLocalName) { case "PathName": if (!newVal.isEmpty()) fupo.rename(oldVal, newVal); break; case "Label": fupo.newLabel(updateField.getTextContent()); break; case "FrontdoorVisible": fupo.newState(determineDatastreamState(update)); break; } targetElement.setTextContent(updateField.getTextContent()); } } } return fupo; }
From source file:ai.aitia.meme.paramsweep.intellisweepPlugin.JgapGAPlugin.java
private void saveChromosome(final Element gaSettingsElement) { final Document document = gaSettingsElement.getOwnerDocument(); final Element chromosomeElement = document.createElement(CHROMOSOME); gaSettingsElement.appendChild(chromosomeElement); @SuppressWarnings("rawtypes") final Enumeration nodes = ((DefaultMutableTreeNode) chromosomeTree.getRoot()).children(); while (nodes.hasMoreElements()) { final DefaultMutableTreeNode node = (DefaultMutableTreeNode) nodes.nextElement(); saveParameterOrGene(node, chromosomeElement); }/*from w ww . j a v a2s .c o m*/ }
From source file:ai.aitia.meme.paramsweep.intellisweepPlugin.JgapGAPlugin.java
private void saveSelectors(final Element gaSettingsElement) { final Document document = gaSettingsElement.getOwnerDocument(); final Element selectorsElement = document.createElement(SELECTORS); gaSettingsElement.appendChild(selectorsElement); for (final IGASelectorConfigurator selectorOperator : selectedSelectionOperators) { final Element selectorElement = document.createElement(SELECTOR); selectorsElement.appendChild(selectorElement); selectorElement.setAttribute(WizardSettingsManager.TYPE, selectorOperator.getName()); for (final Entry<String, String> entry : selectorOperator.getConfiguration().entrySet()) { final Element propertyElement = document.createElement(PROPERTY); propertyElement.setAttribute(KEY, entry.getKey()); propertyElement.appendChild(document.createTextNode(entry.getValue())); selectorElement.appendChild(propertyElement); }/* w w w. j a v a 2 s . co m*/ } }
From source file:ai.aitia.meme.paramsweep.intellisweepPlugin.JgapGAPlugin.java
private void saveOperators(final Element gaSettingsElement) { final Document document = gaSettingsElement.getOwnerDocument(); final Element geneticOperatorsElement = document.createElement(GENETIC_OPERATORS); gaSettingsElement.appendChild(geneticOperatorsElement); for (final IGAOperatorConfigurator geneticOperator : selectedGeneticOperators) { final Element operatorElement = document.createElement(GENETIC_OPERATOR); geneticOperatorsElement.appendChild(operatorElement); operatorElement.setAttribute(WizardSettingsManager.TYPE, geneticOperator.getName()); for (final Entry<String, String> entry : geneticOperator.getConfiguration().entrySet()) { final Element propertyElement = document.createElement(PROPERTY); propertyElement.setAttribute(KEY, entry.getKey()); propertyElement.appendChild(document.createTextNode(entry.getValue())); operatorElement.appendChild(propertyElement); }// ww w .j a v a 2 s. c om } }
From source file:ai.aitia.meme.paramsweep.intellisweepPlugin.JgapGAPlugin.java
private void saveGeneralParameters(final Element gaSettingsElement) { final Document document = gaSettingsElement.getOwnerDocument(); Element element = document.createElement(POPULATION_SIZE); element.appendChild(document.createTextNode(String.valueOf(populationSize))); gaSettingsElement.appendChild(element); element = document.createElement(POPULATION_RANDOM_SEED); element.appendChild(document.createTextNode(String.valueOf(populationGenerationSeed))); gaSettingsElement.appendChild(element); element = document.createElement(FIX_NUMBER_OF_GENERATIONS); element.appendChild(document.createTextNode(String.valueOf(fixNumberOfGenerations))); gaSettingsElement.appendChild(element); if (fixNumberOfGenerations) { element = document.createElement(NUMBER_OF_GENERATIONS); element.appendChild(document.createTextNode(String.valueOf(numberOfGenerations))); gaSettingsElement.appendChild(element); } else {// w w w . j a v a 2 s . c o m element = document.createElement(FITNESS_LIMIT_CRITERION); element.appendChild(document.createTextNode(String.valueOf(fitnessLimitCriterion))); gaSettingsElement.appendChild(element); } element = document.createElement(OPTIMIZATION_DIRECTION); element.appendChild(document.createTextNode(optimizationDirection.name())); gaSettingsElement.appendChild(element); element = document.createElement(FITNESS_FUNCTION); element.setAttribute(WizardSettingsManager.ALIAS, selectedFunction.getName()); element.appendChild(document.createTextNode(selectedFunction.getAccessibleName())); gaSettingsElement.appendChild(element); }
From source file:ai.aitia.meme.paramsweep.intellisweepPlugin.JgapGAPlugin.java
private void saveParameterOrGene(final DefaultMutableTreeNode node, final Element chromosomeElement) { final Document document = chromosomeElement.getOwnerDocument(); final ParameterOrGene userObj = (ParameterOrGene) node.getUserObject(); final ParameterInfo info = userObj.getInfo(); if (userObj.isGene()) { final GeneInfo geneInfo = userObj.getGeneInfo(); final Element geneElement = document.createElement(GENE); chromosomeElement.appendChild(geneElement); geneElement.setAttribute(WizardSettingsManager.NAME, info.getName()); geneElement.setAttribute(WizardSettingsManager.TYPE, geneInfo.getValueType()); if (GeneInfo.INTERVAL.equals(geneInfo.getValueType())) { geneElement.setAttribute(IS_INTEGER, String.valueOf(geneInfo.isIntegerVals())); geneElement.setAttribute(MIN_VALUE, String.valueOf(geneInfo.getMinValue())); geneElement.setAttribute(MAX_VALUE, String.valueOf(geneInfo.getMaxValue())); } else if (GeneInfo.LIST.equals(geneInfo.getValueType())) { for (final Object value : geneInfo.getValueRange()) { final Element element = document.createElement(LIST_VALUE); geneElement.appendChild(element); element.appendChild(document.createTextNode(String.valueOf(value))); }//from ww w .java2 s. c o m } } else { final Element paramElement = document.createElement(PARAMETER); chromosomeElement.appendChild(paramElement); paramElement.setAttribute(WizardSettingsManager.NAME, info.getName()); paramElement.appendChild(document.createTextNode(String.valueOf(info.getValue()))); } }
From source file:com.twinsoft.convertigo.beans.steps.TransactionStep.java
@Override public void configure(Element element) throws Exception { super.configure(element); String version = element.getAttribute("version"); if (version == null) { String s = XMLUtils.prettyPrintDOM(element); EngineException ee = new EngineException( "Unable to find version number for the database object \"" + getName() + "\".\nXML data: " + s); throw ee; }/*w w w .j av a 2s .co m*/ try { if (VersionUtils.compare(version, "6.0.3") < 0) { String projectName = (String) XMLUtils.findPropertyValue(element, "projectName"); // Handle wrong project name if (projectName.equals("")) { projectName = "unknown_project"; } String connectorName = (String) XMLUtils.findPropertyValue(element, "connectorName"); // If the default connector has been set, find the explicit default connector name if (connectorName.equals("")) { NodeList connectorsNodeList = element.getOwnerDocument().getElementsByTagName("connector"); Node connectorNode = XMLUtils.findNodeByAttributeValue(connectorsNodeList, "default", "true"); if (connectorNode != null) { connectorName = (String) XMLUtils.findPropertyValue((Element) connectorNode, "name"); } else { throw new EngineException( "Unable to find the default connector for the project '" + projectName + "'"); } } String transactionName = (String) XMLUtils.findPropertyValue(element, "transactionName"); // If the default transaction has been set, find the explicit default transaction name if (transactionName.equals("")) { NodeList connectorsNodeList = element.getOwnerDocument().getElementsByTagName("connector"); int nlLen = connectorsNodeList.getLength(); for (int i = 0; i < nlLen; i++) { Element connectorElement = (Element) connectorsNodeList.item(i); String connectorNameElement = (String) XMLUtils.findPropertyValue(connectorElement, "name"); if (connectorName.equals(connectorNameElement)) { NodeList transactionsNodeList = connectorElement.getElementsByTagName("transaction"); Node transactionNode = XMLUtils.findNodeByAttributeValue(transactionsNodeList, "default", "true"); if (transactionNode != null) { transactionName = (String) XMLUtils.findPropertyValue((Element) transactionNode, "name"); break; } throw new EngineException("Unable to find the default transaction for the connector '" + connectorName + "' from project '" + projectName + "'"); } } } String sourceTransaction = projectName + SequenceStep.SOURCE_SEPARATOR + connectorName + SequenceStep.SOURCE_SEPARATOR + transactionName; setSourceTransaction(sourceTransaction); hasChanged = true; Engine.logBeans.warn("[SequenceStpe] The object \"" + getName() + "\" has been updated to version 6.0.3; source transaction: " + sourceTransaction); } } catch (Exception e) { throw new EngineException( "Unable to migrate the source definition for CallTransaction step \"" + getName() + "\".", e); } }
From source file:com.enonic.vertical.adminweb.ContentObjectHandlerServlet.java
private void addStyleSheet(Element contentobjectElem, String elemName, ResourceKey styleSheetKey) throws VerticalAdminException { ResourceFile resource = resourceService.getResourceFile(styleSheetKey); if (resource == null) { throw new StylesheetNotFoundException(styleSheetKey); }/*w w w .ja v a2 s .co m*/ Document styleSheetDoc; try { styleSheetDoc = resource.getDataAsXml().getAsDOMDocument(); } catch (XMLException e) { throw new InvalidStylesheetException(styleSheetKey, e); } Element styleSheetRoot = styleSheetDoc.getDocumentElement(); String attr = styleSheetRoot.getAttribute("xmlns:xsl"); styleSheetRoot.removeAttribute("xmlns:xsl"); styleSheetRoot.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:xsl", attr); Document doc = contentobjectElem.getOwnerDocument(); Element elem = XMLTool.createElement(doc, contentobjectElem, elemName); elem.appendChild(doc.importNode(styleSheetRoot, true)); }