List of usage examples for org.w3c.dom Element hashCode
@HotSpotIntrinsicCandidate public native int hashCode();
From source file:com.clican.pluto.dataprocess.spring.parser.DeployParser.java
public BeanDefinition parse(Element element, ParserContext parserContext) { BeanDefinitionRegistry bdr = parserContext.getRegistry(); RootBeanDefinition beanDef = new RootBeanDefinition(); beanDef.setAbstract(false);//from w w w . j a v a2s . co m beanDef.setBeanClass(Deploy.class); beanDef.setLazyInit(false); beanDef.setAutowireMode(Autowire.BY_NAME.value()); String id = element.getAttribute("id"); if (StringUtils.isEmpty(id)) { id = "dplDeploy#" + element.hashCode(); } bdr.registerBeanDefinition(id, beanDef); this.setBeanDefinitionStringProperty("name", beanDef, element); this.setBeanDefinitionStringProperty("url", beanDef, element); this.setBeanDefinitionStringProperty("propertyResources", beanDef, element); return beanDef; }
From source file:eu.europa.esig.dss.xades.validation.XAdESSignature.java
/** * This method returns the last timestamp validation data for an archive timestamp. * * @return// w w w.j a va 2 s .c o m */ public Element getLastTimestampValidationData() { final List<TimestampToken> archiveTimestamps = getArchiveTimestamps(); TimestampToken mostRecentTimestamp = null; for (final TimestampToken archiveTimestamp : archiveTimestamps) { if (mostRecentTimestamp == null) { mostRecentTimestamp = archiveTimestamp; continue; } final Date generationTime = archiveTimestamp.getGenerationTime(); final Date mostRecentGenerationTime = mostRecentTimestamp.getGenerationTime(); if (generationTime.after(mostRecentGenerationTime)) { mostRecentTimestamp = archiveTimestamp; } } final int timestampHashCode = mostRecentTimestamp.getHashCode(); final NodeList nodeList = DSSXMLUtils.getNodeList(signatureElement, xPathQueryHolder.XPATH_UNSIGNED_SIGNATURE_PROPERTIES + "/*"); boolean found = false; for (int ii = 0; ii < nodeList.getLength(); ii++) { final Element unsignedSignatureElement = (Element) nodeList.item(ii); final int nodeHashCode = unsignedSignatureElement.hashCode(); if (nodeHashCode == timestampHashCode) { found = true; } else if (found) { final String nodeName = unsignedSignatureElement.getLocalName(); if ("TimeStampValidationData".equals(nodeName)) { return unsignedSignatureElement; } } } return null; }
From source file:com.netspective.sparx.util.xml.XmlSource.java
public void inheritNodes(Element element, Map sourcePool, String attrName, Set excludeElems) { String inheritAttr = element.getAttribute(attrName); while (inheritAttr != null && inheritAttr.length() > 0) { Element inheritFromElem = null; StringTokenizer inheritST = new StringTokenizer(inheritAttr, ","); String[] inherits = new String[15]; int inheritsCount = 0; while (inheritST.hasMoreTokens()) { inherits[inheritsCount] = inheritST.nextToken(); inheritsCount++;//from www . ja v a 2s .c o m } /** we're going to work backwards because we want to make sure the * elements are added in the appropriate order (same order as the * inheritance list) */ for (int j = (inheritsCount - 1); j >= 0; j--) { String inheritType = inherits[j]; inheritFromElem = (Element) sourcePool.get(inheritType); if (inheritFromElem == null) { errors.add("can not extend '" + element.getAttribute("name") + "' from '" + inheritType + "': source not found"); continue; } /* don't inherit the same objects more than once */ String inheritanceId = Integer.toString(element.hashCode()) + '.' + Integer.toString(inheritFromElem.hashCode()); if (inheritanceHistorySet.contains(inheritanceId)) { errors.add("Attempting to copy duplicate node: " + inheritanceId + ", " + element.getTagName() + ", " + element.getAttribute("name") + ", " + inheritFromElem.getTagName()); //continue; } inheritanceHistorySet.add(inheritanceId); Element extendsElem = xmlDoc.createElement("extends"); extendsElem.appendChild(xmlDoc.createTextNode(inheritType)); element.appendChild(extendsElem); inheritElement(inheritFromElem, element, excludeElems, inheritType); } // find the next one if we have more parents if (inheritFromElem != null) inheritAttr = inheritFromElem.getAttribute(attrName); else inheritAttr = null; } }
From source file:eu.europa.esig.dss.xades.validation.XAdESSignature.java
/** * This method creates {@code TimestampToken} based on provided parameters. * * @param timestampElement/*from w w w .j ava 2s . c o m*/ * contains the encapsulated timestamp * @param timestampType * {@code TimestampType} * @return {@code TimestampToken} of the given type * @throws DSSException */ private TimestampToken makeTimestampToken(final Element timestampElement, final TimestampType timestampType) throws DSSException { final Element timestampTokenNode = DSSXMLUtils.getElement(timestampElement, xPathQueryHolder.XPATH__ENCAPSULATED_TIMESTAMP); if (timestampTokenNode == null) { // TODO (09/11/2014): The error message must be propagated to the // validation report LOG.warn("The timestamp (" + timestampType.name() + ") cannot be extracted from the signature!"); return null; } final String base64EncodedTimestamp = timestampTokenNode.getTextContent(); final TimeStampToken timeStampToken = createTimeStampToken(base64EncodedTimestamp); final TimestampToken timestampToken = new TimestampToken(timeStampToken, timestampType, certPool); timestampToken.setHashCode(timestampElement.hashCode()); setTimestampCanonicalizationMethod(timestampElement, timestampToken); // TODO: timestampToken.setIncludes(element.getIncludes)... // final NodeList includes = // timestampTokenNode.getElementsByTagName("Include"); // for (int i = 0; i < includes.getLength(); ++i) { // timestampToken.getTimestampIncludes().add(new // TimestampInclude(includes.item(i).getBaseURI(), // includes.item(i).getAttributes())); // } return timestampToken; }
From source file:org.eclipse.winery.repository.importing.CSARImporter.java
/** * Imports the specified types into the repository. The types are converted to an import statement * /*w w w.j av a 2 s. c o m*/ * @param errors Container for error messages */ private void importTypes(TDefinitions defs, final List<String> errors) { Types typesContainer = defs.getTypes(); if (typesContainer != null) { List<Object> types = typesContainer.getAny(); for (Object type : types) { if (type instanceof Element) { Element element = (Element) type; // generate id part of ImportId out of definitions' id // we do not use the name as the name has to be URLencoded again and we have issues with // the interplay with // org.eclipse.winery.common.ids.definitions.imports.GenericImportId.getId(TImport) then. String id = defs.getId(); // try to make the id unique by hashing the "content" of the definition id = id + "-" + Integer.toHexString(element.hashCode()); // set importId TOSCAComponentId importId; String ns; if (element.getNamespaceURI().equals(XMLConstants.W3C_XML_SCHEMA_NS_URI)) { ns = element.getAttribute("targetNamespace"); importId = new XSDImportId(ns, id, false); } else { // Quick hack for non-XML-Schema-definitions ns = "unknown"; importId = new GenericImportId(ns, id, false, element.getNamespaceURI()); } // Following code is adapted from importOtherImports TDefinitions wrapperDefs = BackendUtils.createWrapperDefinitions(importId); TImport imp = new TImport(); String fileName = id + ".xsd"; imp.setLocation(fileName); imp.setImportType(XMLConstants.W3C_XML_SCHEMA_NS_URI); imp.setNamespace(ns); wrapperDefs.getImport().add(imp); CSARImporter.storeDefinitions(importId, wrapperDefs); // put the file itself to the repo // ref is required to generate fileRef RepositoryFileReference ref = BackendUtils.getRefOfDefinitions(importId); RepositoryFileReference fileRef = new RepositoryFileReference(ref.getParent(), fileName); // convert element to document // QUICK HACK. Alternative: Add new method Repository.INSTANCE.getOutputStream and // transform DOM node to OuptputStream String content = Util.getXMLAsString(element); try { Repository.INSTANCE.putContentToFile(fileRef, content, MediaType.APPLICATION_XML_TYPE); } catch (IOException e) { CSARImporter.logger .debug("Could not put XML Schema definition to file " + fileRef.toString(), e); errors.add("Could not put XML Schema definition to file " + fileRef.toString()); } // add import to definitions // adapt path - similar to importOtherImport String newLoc = "../" + Utils.getURLforPathInsideRepo(BackendUtils.getPathInsideRepo(fileRef)); imp.setLocation(newLoc); defs.getImport().add(imp); } else { // This is a known type. Otherwise JAX-B would render it as Element errors.add("There is a Type of class " + type.getClass().toString() + " which is unknown to Winery. The type element is imported as is"); } } } }
From source file:org.infoglue.cms.applications.structuretool.actions.ViewSiteNodePageComponentsAction.java
/** * This method adds a component to the page. *///from ww w. ja v a 2 s.c o m public String doMoveComponentToSlot() throws Exception { logger.info("************************************************************"); logger.info("* MOVING COMPONENT TO ANOTHER SLOT *"); logger.info("************************************************************"); logger.info("siteNodeId:" + this.siteNodeId); logger.info("languageId:" + this.languageId); logger.info("contentId:" + this.contentId); logger.info("queryString:" + this.getRequest().getQueryString()); logger.info("parentComponentId:" + this.parentComponentId); logger.info("componentId:" + this.componentId); logger.info("slotId:" + this.slotId); logger.info("specifyBaseTemplate:" + this.specifyBaseTemplate); initialize(); logger.info("masterLanguageId:" + this.masterLanguageVO.getId()); ContentVO componentContentVO = null; if (this.specifyBaseTemplate.equalsIgnoreCase("true")) { throw new SystemException("Not possible to move component to base slot"); } else { String componentXML = getPageComponentsString(siteNodeId, this.masterLanguageVO.getId()); Document document = XMLHelper.readDocumentFromByteArray(componentXML.getBytes("UTF-8")); String componentXPath = "//component[@id=" + this.componentId + "]"; String parentComponentXPath = "//component[@id=" + this.parentComponentId + "]/components"; logger.info("componentXPath:" + componentXPath); logger.info("parentComponentXPath:" + parentComponentXPath); Node componentNode = org.apache.xpath.XPathAPI.selectSingleNode(document.getDocumentElement(), componentXPath); logger.info("Found componentNode:" + componentNode); Node parentComponentComponentsNode = org.apache.xpath.XPathAPI .selectSingleNode(document.getDocumentElement(), parentComponentXPath); logger.info("Found parentComponentComponentsNode:" + parentComponentComponentsNode); if (componentNode != null && parentComponentComponentsNode != null) { Element component = (Element) componentNode; Element currentParentElement = (Element) componentNode.getParentNode(); Element parentComponentComponentsElement = (Element) parentComponentComponentsNode; Element parentComponentElement = (Element) parentComponentComponentsNode.getParentNode(); Integer componentContentId = new Integer(component.getAttribute("contentId")); Integer parentComponentContentId = new Integer(parentComponentElement.getAttribute("contentId")); logger.info("componentContentId:" + componentContentId); logger.info("parentComponentContentId:" + parentComponentContentId); componentContentVO = ContentController.getContentController() .getContentVOWithId(componentContentId); PageEditorHelper peh = new PageEditorHelper(); List<Slot> slots = peh.getSlots(parentComponentContentId, languageId, this.getInfoGluePrincipal()); boolean allowed = true; Iterator<Slot> slotsIterator = slots.iterator(); while (slotsIterator.hasNext()) { Slot slot = slotsIterator.next(); logger.info(slot.getId() + "=" + slotId); if (slot.getId().equals(slotId)) { String[] allowedComponentNames = slot.getAllowedComponentsArray(); String[] disallowedComponentNames = slot.getDisallowedComponentsArray(); if (allowedComponentNames != null && allowedComponentNames.length > 0) { allowed = false; for (int i = 0; i < allowedComponentNames.length; i++) { if (allowedComponentNames[i].equalsIgnoreCase(componentContentVO.getName())) allowed = true; } } if (disallowedComponentNames != null && disallowedComponentNames.length > 0) { for (int i = 0; i < disallowedComponentNames.length; i++) { if (disallowedComponentNames[i].equalsIgnoreCase(componentContentVO.getName())) allowed = false; } } } break; } logger.info("Should the component:" + componentContentVO + " be allowed to be put in " + slotId + ":" + allowed); logger.info("currentParentElement:" + currentParentElement.getNodeName() + ":" + currentParentElement.hashCode()); logger.info("parentComponentComponentsElement:" + parentComponentComponentsElement.getNodeName() + ":" + parentComponentComponentsElement.hashCode()); logger.info("slotPositionComponentId:" + slotPositionComponentId); if ((component.getParentNode() == parentComponentComponentsElement && slotId.equalsIgnoreCase(component.getAttribute("name")))) { logger.info("Yes..."); component.getParentNode().removeChild(component); component.setAttribute("name", slotId); logger.info("slotPositionComponentId:" + slotPositionComponentId); if (slotPositionComponentId != null && !slotPositionComponentId.equals("")) { logger.info("Moving component to slot: " + slotPositionComponentId); Element afterElement = null; NodeList childNodes = parentComponentComponentsElement.getChildNodes(); for (int i = 0; i < childNodes.getLength(); i++) { Node node = childNodes.item(i); if (node.getNodeType() == Node.ELEMENT_NODE) { Element element = (Element) node; if (element.getAttribute("id").equals(slotPositionComponentId)) { afterElement = element; break; } } } if (afterElement != null) { logger.info("Inserting component before: " + afterElement); parentComponentComponentsElement.insertBefore(component, afterElement); } else { parentComponentComponentsElement.appendChild(component); } } else { logger.info("Appending component..."); parentComponentComponentsElement.appendChild(component); } String modifiedXML = XMLHelper.serializeDom(document, new StringBuffer()).toString(); ContentVO contentVO = NodeDeliveryController .getNodeDeliveryController(siteNodeId, this.masterLanguageVO.getId(), 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=" + componentId + "&componentContentId=" + componentContentVO.getId() + "&showSimple=" + this.showSimple; } else if (allowed && (component.getParentNode() != parentComponentComponentsElement || !slotId.equalsIgnoreCase(component.getAttribute("name")))) { logger.info("Moving component..."); component.getParentNode().removeChild(component); component.setAttribute("name", slotId); if (slotPositionComponentId != null && !slotPositionComponentId.equals("")) { NodeList childNodes = parentComponentComponentsElement.getChildNodes(); for (int i = 0; i < childNodes.getLength(); i++) { Node node = childNodes.item(i); if (node.getNodeType() == Node.ELEMENT_NODE) { Element element = (Element) node; if (element.getAttribute("id").equals(slotPositionComponentId)) { logger.info("Inserting component before: " + element); parentComponentComponentsElement.insertBefore(component, element); break; } } } } else { parentComponentComponentsElement.appendChild(component); } String modifiedXML = XMLHelper.serializeDom(document, new StringBuffer()).toString(); ContentVO contentVO = NodeDeliveryController .getNodeDeliveryController(siteNodeId, this.masterLanguageVO.getId(), 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=" + componentId + "&componentContentId=" + componentContentVO.getId() + "&showSimple=" + this.showSimple; } else { this.url = getComponentRendererUrl() + getComponentRendererAction() + "?siteNodeId=" + this.siteNodeId + "&languageId=" + this.languageId + "&contentId=" + this.contentId + "&showSimple=" + this.showSimple; } } } //this.getResponse().sendRedirect(url); this.url = this.getResponse().encodeURL(url); this.getResponse().sendRedirect(url); return NONE; }
From source file:org.wso2.carbon.identity.sts.GenericTokenIssuer.java
/** * Encrypt the given SAML Assertion element with the given key information. * /*from w w w .ja v a 2 s . c o m*/ * @param doc * @param assertionElement * @param encryptedKey */ private void encryptSAMLAssertion(Document doc, Element assertionElement, WSSecEncryptedKey encryptedKey) throws TrustException { XMLCipher xmlCipher = null; SecretKey secretKey = null; String xencEncryptedDataId = null; KeyInfo keyInfo = null; EncryptedData encData = null; try { xmlCipher = XMLCipher.getInstance(WSConstants.AES_256); secretKey = WSSecurityUtil.prepareSecretKey(WSConstants.AES_256, encryptedKey.getEphemeralKey()); xmlCipher.init(XMLCipher.ENCRYPT_MODE, secretKey); xencEncryptedDataId = "EncDataId-" + assertionElement.hashCode(); keyInfo = new KeyInfo(doc); keyInfo.addUnknownElement(encryptedKey.getEncryptedKeyElement()); encData = xmlCipher.getEncryptedData(); encData.setId(xencEncryptedDataId); encData.setKeyInfo(keyInfo); xmlCipher.doFinal(doc, assertionElement, false); } catch (Exception e) { throw new TrustException(TrustException.REQUEST_FAILED, e); } }