List of usage examples for org.w3c.dom Element getLastChild
public Node getLastChild();
From source file:com.hpe.application.automation.tools.results.RunResultRecorder.java
private void processSlaRule(JobLrScenarioResult jobLrScenarioResult, Element slaRuleElement, LrTest.SLA_GOAL slaGoal) {/*www. j av a 2s. c o m*/ switch (slaGoal) { case AverageThroughput: WholeRunResult averageThroughput = new WholeRunResult(); averageThroughput.setSlaGoal(LrTest.SLA_GOAL.AverageThroughput); averageThroughput.setActualValue(Double.valueOf(slaRuleElement.getAttribute(SLA_ACTUAL_VALUE_LABEL))); averageThroughput.setGoalValue(Double.valueOf(slaRuleElement.getAttribute(SLA_GOAL_VALUE_LABEL))); averageThroughput.setFullName(slaRuleElement.getAttribute(SLA_ULL_NAME)); averageThroughput.setStatus( LrTest.SLA_STATUS.checkStatus(slaRuleElement.getLastChild().getTextContent().trim())); jobLrScenarioResult.scenarioSlaResults.add(averageThroughput); break; case TotalThroughput: WholeRunResult totalThroughput = new WholeRunResult(); totalThroughput.setSlaGoal(LrTest.SLA_GOAL.TotalThroughput); totalThroughput.setActualValue(Double.valueOf(slaRuleElement.getAttribute(SLA_ACTUAL_VALUE_LABEL))); totalThroughput.setGoalValue(Double.valueOf(slaRuleElement.getAttribute(SLA_GOAL_VALUE_LABEL))); totalThroughput.setFullName(slaRuleElement.getAttribute(SLA_ULL_NAME)); totalThroughput.setStatus( LrTest.SLA_STATUS.checkStatus(slaRuleElement.getLastChild().getTextContent().trim())); jobLrScenarioResult.scenarioSlaResults.add(totalThroughput); break; case AverageHitsPerSecond: WholeRunResult averageHitsPerSecond = new WholeRunResult(); averageHitsPerSecond.setSlaGoal(LrTest.SLA_GOAL.AverageHitsPerSecond); averageHitsPerSecond .setActualValue(Double.valueOf(slaRuleElement.getAttribute(SLA_ACTUAL_VALUE_LABEL))); averageHitsPerSecond.setGoalValue(Double.valueOf(slaRuleElement.getAttribute(SLA_GOAL_VALUE_LABEL))); averageHitsPerSecond.setFullName(slaRuleElement.getAttribute(SLA_ULL_NAME)); averageHitsPerSecond.setStatus( LrTest.SLA_STATUS.checkStatus(slaRuleElement.getLastChild().getTextContent().trim())); jobLrScenarioResult.scenarioSlaResults.add(averageHitsPerSecond); break; case TotalHits: WholeRunResult totalHits = new WholeRunResult(); totalHits.setSlaGoal(LrTest.SLA_GOAL.TotalHits); totalHits.setActualValue(Double.valueOf(slaRuleElement.getAttribute(SLA_ACTUAL_VALUE_LABEL))); totalHits.setGoalValue(Double.valueOf(slaRuleElement.getAttribute(SLA_GOAL_VALUE_LABEL))); totalHits.setFullName(slaRuleElement.getAttribute(SLA_ULL_NAME)); totalHits.setStatus( LrTest.SLA_STATUS.checkStatus(slaRuleElement.getLastChild().getTextContent().trim())); jobLrScenarioResult.scenarioSlaResults.add(totalHits); break; case ErrorsPerSecond: TimeRangeResult errPerSec = new AvgTransactionResponseTime(); errPerSec.setSlaGoal(LrTest.SLA_GOAL.ErrorsPerSecond); errPerSec.setFullName(slaRuleElement.getAttribute(SLA_ULL_NAME)); errPerSec.setLoadThrashold(slaRuleElement.getAttribute("SLALoadThresholdValue")); errPerSec.setStatus( LrTest.SLA_STATUS.checkStatus(slaRuleElement.getLastChild().getTextContent().trim())); //Might not work due to time ranges addTimeRanges(errPerSec, slaRuleElement); jobLrScenarioResult.scenarioSlaResults.add(errPerSec); break; case PercentileTRT: PercentileTransactionWholeRun percentileTransactionWholeRun = new PercentileTransactionWholeRun(); percentileTransactionWholeRun.setSlaGoal(LrTest.SLA_GOAL.PercentileTRT); percentileTransactionWholeRun.setName(slaRuleElement.getAttribute("TransactionName")); percentileTransactionWholeRun .setActualValue(Double.valueOf(slaRuleElement.getAttribute(SLA_ACTUAL_VALUE_LABEL))); percentileTransactionWholeRun .setGoalValue(Double.valueOf(slaRuleElement.getAttribute(SLA_GOAL_VALUE_LABEL))); percentileTransactionWholeRun.setFullName(slaRuleElement.getAttribute(SLA_ULL_NAME)); percentileTransactionWholeRun.setPrecentage(Double.valueOf(slaRuleElement.getAttribute("Percentile"))); percentileTransactionWholeRun.setStatus( LrTest.SLA_STATUS.checkStatus(slaRuleElement.getLastChild().getTextContent().trim())); jobLrScenarioResult.scenarioSlaResults.add(percentileTransactionWholeRun); break; case AverageTRT: AvgTransactionResponseTime transactionTimeRange = new AvgTransactionResponseTime(); transactionTimeRange.setSlaGoal(LrTest.SLA_GOAL.AverageTRT); transactionTimeRange.setName(slaRuleElement.getAttribute("TransactionName")); transactionTimeRange.setFullName(slaRuleElement.getAttribute(SLA_ULL_NAME)); transactionTimeRange.setLoadThrashold(slaRuleElement.getAttribute("SLALoadThresholdValue")); transactionTimeRange.setStatus( LrTest.SLA_STATUS.checkStatus(slaRuleElement.getLastChild().getTextContent().trim())); //Might not work due to time ranges addTimeRanges(transactionTimeRange, slaRuleElement); jobLrScenarioResult.scenarioSlaResults.add(transactionTimeRange); break; case Bad: break; } }
From source file:org.etudes.tool.melete.ViewSectionsPage.java
private Node getInnerLastChild(Element secElement) { if (secElement.getLastChild().hasChildNodes() == false) { return secElement.getLastChild(); } else {//from w ww . j a v a2s . com return getInnerLastChild((Element) secElement.getLastChild()); } }
From source file:org.smartfrog.avalanche.client.sf.apps.gt4.javawscore.utils.EditXML.java
/** * Adds a child node as the last child to a parent node * @param parent/* w ww .j a v a 2s. com*/ * @param child */ public void addLastChild(Element parent, Element child) { Node lastChild = parent.getLastChild(); if (child.getNodeName() == lastChild.getNodeName()) { parent.replaceChild(child, lastChild); } else { parent.appendChild(child); } }
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 www .java 2s. c om*/ * @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); } }
From source file:ru.codeinside.gws.crypto.cryptopro.CryptoProvider.java
@Override public String signElement(String sourceXML, String elementName, String namespace, boolean removeIdAttribute, boolean signatureAfterElement, boolean inclusive) throws Exception { loadCertificate();//from w ww . jav a 2s.com DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setIgnoringElementContentWhitespace(true); dbf.setCoalescing(true); dbf.setNamespaceAware(true); DocumentBuilder documentBuilder = dbf.newDocumentBuilder(); InputSource is = new InputSource(new StringReader(sourceXML)); Document doc = documentBuilder.parse(is); Element elementForSign = (Element) doc.getElementsByTagNameNS(namespace, elementName).item(0); Node parentNode = null; Element detachedElementForSign; Document detachedDocument; if (!elementForSign.isSameNode(doc.getDocumentElement())) { parentNode = elementForSign.getParentNode(); parentNode.removeChild(elementForSign); detachedDocument = documentBuilder.newDocument(); Node importedElementForSign = detachedDocument.importNode(elementForSign, true); detachedDocument.appendChild(importedElementForSign); detachedElementForSign = detachedDocument.getDocumentElement(); } else { detachedElementForSign = elementForSign; detachedDocument = doc; } String signatureMethodUri = inclusive ? "urn:ietf:params:xml:ns:cpxmlsec:algorithms:gostr34102001-gostr3411" : "http://www.w3.org/2001/04/xmldsig-more#gostr34102001-gostr3411"; String canonicalizationMethodUri = inclusive ? "http://www.w3.org/TR/2001/REC-xml-c14n-20010315" : "http://www.w3.org/2001/10/xml-exc-c14n#"; XMLSignature sig = new XMLSignature(detachedDocument, "", signatureMethodUri, canonicalizationMethodUri); if (!removeIdAttribute) { detachedElementForSign.setAttribute("Id", detachedElementForSign.getTagName()); } if (signatureAfterElement) detachedElementForSign.insertBefore(sig.getElement(), detachedElementForSign.getLastChild().getNextSibling()); else { detachedElementForSign.insertBefore(sig.getElement(), detachedElementForSign.getFirstChild()); } Transforms transforms = new Transforms(detachedDocument); transforms.addTransform("http://www.w3.org/2000/09/xmldsig#enveloped-signature"); transforms.addTransform(inclusive ? "http://www.w3.org/TR/2001/REC-xml-c14n-20010315#WithComments" : "http://www.w3.org/2001/10/xml-exc-c14n#"); String digestURI = inclusive ? "urn:ietf:params:xml:ns:cpxmlsec:algorithms:gostr3411" : "http://www.w3.org/2001/04/xmldsig-more#gostr3411"; sig.addDocument(removeIdAttribute ? "" : "#" + detachedElementForSign.getTagName(), transforms, digestURI); sig.addKeyInfo(cert); sig.sign(privateKey); if ((!elementForSign.isSameNode(doc.getDocumentElement())) && (parentNode != null)) { Node signedNode = doc.importNode(detachedElementForSign, true); parentNode.appendChild(signedNode); } TransformerFactory tf = TransformerFactory.newInstance(); Transformer trans = tf.newTransformer(); trans.setOutputProperty("omit-xml-declaration", "yes"); StringWriter stringWriter = new StringWriter(); StreamResult streamResult = new StreamResult(stringWriter); trans.transform(new DOMSource(doc), streamResult); return stringWriter.toString(); }
From source file:wssec.TestEncryptedKeyProcessor.java
private void verify(Element enc) { // Change the CipherValue of the key String str = enc.getLastChild().getFirstChild().getTextContent(); enc.getLastChild().getFirstChild().setTextContent(Base64.encode(str.getBytes())); EncryptedKeyProcessor encryptedKeyProcessor = new EncryptedKeyProcessor(); try {/*w ww . j a v a 2s . c om*/ encryptedKeyProcessor.handleEncryptedKey(enc, this, crypto, null); } catch (Exception e) { LOG.error("Key validation error, Should create a new random key if key decrypting fails "); } }