List of usage examples for org.w3c.dom Element getElementsByTagNameNS
public NodeList getElementsByTagNameNS(String namespaceURI, String localName) throws DOMException;
NodeList
of all the descendant Elements
with a given local name and namespace URI in document order. From source file:eu.domibus.ebms3.receiver.SetPolicyInInterceptor.java
/** * Intercepts a message./*w w w . j a v a 2 s . c o m*/ * Interceptors should NOT invoke handleMessage or handleFault * on the next interceptor - the interceptor chain will * take care of this. * * @param message the incoming message to handle */ @Override public void handleMessage(SoapMessage message) throws Fault { String pmodeKey = null; InputStream inputStream = message.getContent(InputStream.class); ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); try { IOUtils.copy(inputStream, byteArrayOutputStream); byte[] data = byteArrayOutputStream.toByteArray(); message.setContent(InputStream.class, new ByteArrayInputStream(data)); new StaxInInterceptor().handleMessage(message); XMLStreamReader xmlStreamReader = message.getContent(XMLStreamReader.class); Element soapEnvelope = new StaxToDOMConverter().convert(xmlStreamReader); message.removeContent(XMLStreamReader.class); message.setContent(InputStream.class, new ByteArrayInputStream(data)); //message.setContent(XMLStreamReader.class, XMLInputFactory.newInstance().createXMLStreamReader(message.getContent(InputStream.class))); Node messagingNode = soapEnvelope .getElementsByTagNameNS(ObjectFactory._Messaging_QNAME.getNamespaceURI(), ObjectFactory._Messaging_QNAME.getLocalPart()) .item(0); Messaging messaging = ((JAXBElement<Messaging>) this.jaxbContext.createUnmarshaller() .unmarshal(messagingNode)).getValue(); pmodeKey = this.pModeProvider.findPModeKeyForUserMesssage(messaging.getUserMessage()); // FIXME: This does not work for signalmessages LegConfiguration legConfiguration = this.pModeProvider.getLegConfiguration(pmodeKey); PolicyBuilder builder = message.getExchange().getBus().getExtension(PolicyBuilder.class); Policy policy = builder .getPolicy(new FileInputStream(new File(System.getProperty("domibus.config.location"), legConfiguration.getSecurity().getPolicy()))); message.put(MSHDispatcher.PMODE_KEY_CONTEXT_PROPERTY, pmodeKey); //FIXME: Test!!!! message.getExchange().put(MSHDispatcher.PMODE_KEY_CONTEXT_PROPERTY, pmodeKey); //FIXME: Consistent way! If properties are added to the exchange you will have access via PhaseInterceptorChain message.getExchange().put(MessageInfo.MESSAGE_ID_CONTEXT_PROPERTY, messaging.getUserMessage().getMessageInfo().getMessageId()); //FIXME: the exchange is shared by both the request and the response. This would result in a situation where the policy for an incoming request would be used for the response. I think this is what we want message.getExchange().put(PolicyConstants.POLICY_OVERRIDE, policy); message.put(PolicyConstants.POLICY_OVERRIDE, policy); message.getInterceptorChain().add(new SetPolicyInInterceptor.CheckEBMSHeaderInterceptor()); message.getInterceptorChain().add(new SetPolicyInInterceptor.SOAPMessageBuilderInterceptor()); message.put(SecurityConstants.ASYMMETRIC_SIGNATURE_ALGORITHM, legConfiguration.getSecurity().getSignatureMethod().getAlgorithm()); message.getExchange().put(SecurityConstants.ASYMMETRIC_SIGNATURE_ALGORITHM, legConfiguration.getSecurity().getSignatureMethod().getAlgorithm()); } catch (JAXBException | EbMS3Exception e) { SetPolicyInInterceptor.LOG.debug("", e); // Those errors are expected (no PMode found, therefore DEBUG) throw new Fault(e); } catch (IOException | ParserConfigurationException | SAXException e) { SetPolicyInInterceptor.LOG.error("", e); // Those errors are not expected throw new Fault(e); } }
From source file:net.scriptability.core.integration.spring.ScriptAbilityBeanDefinitionParser.java
private String registerScriptAbilityInitialisingBean(final Element configureElement, final String factoryBeanName, final BeanDefinitionRegistry beanDefinitionRegistry) { BeanDefinitionBuilder builder = BeanDefinitionBuilder .genericBeanDefinition(MethodInvokingFactoryBean.class); builder.addPropertyReference("targetObject", DEFAULT_SCRIPTABILITY_BEAN_NAME); builder.addPropertyValue("targetMethod", "start"); List<Object> arguments = new ManagedList(); if (hasBindingsElement(configureElement)) { Map<String, RuntimeBeanReference> bindings = createBeanBindings((Element) configureElement .getElementsByTagNameNS(XML_NAMESPACE__SCRIPTABILITY, XML_ELEMENT__BINDINGS).item(0)); arguments.add(bindings);//from ww w .jav a 2 s . c o m } arguments.add(new RuntimeBeanReference(factoryBeanName)); builder.addPropertyValue("arguments", arguments); return BeanDefinitionReaderUtils.registerWithGeneratedName(builder.getBeanDefinition(), beanDefinitionRegistry); }
From source file:com.evolveum.midpoint.prism.schema.SchemaToDomProcessor.java
private Element getOrCreateElement(QName qName, Element parentElement) { NodeList elements = parentElement.getElementsByTagNameNS(qName.getNamespaceURI(), qName.getLocalPart()); if (elements.getLength() == 0) { Element element = createElement(qName); Element refChild = DOMUtil.getFirstChildElement(parentElement); parentElement.insertBefore(element, refChild); return element; }// ww w . ja v a2 s. co m return (Element) elements.item(0); }
From source file:com.ubikod.capptain.android.sdk.reach.CapptainReachInteractiveContent.java
CapptainReachInteractiveContent(String jid, String rawXml, Element root) throws JSONException { super(jid, rawXml, root); mTitle = XmlUtil.getTagText(root, "title", root.getLocalName()); mActionLabel = XmlUtil.getTagText(root, "label", "action"); mExitLabel = XmlUtil.getTagText(root, "label", "exit"); /* Behavior */ mBehavior = Behavior.ANYTIME;/*from w ww.jav a 2 s .co m*/ Element behavior = XmlUtil.getTag(root, "behavior", null); if (behavior != null) if (XmlUtil.getTag(behavior, "session", null) != null) mBehavior = Behavior.SESSION; else { mAllowedActivities = new HashSet<String>(); NodeList activities = behavior.getElementsByTagNameNS(REACH_NAMESPACE, "activity"); if (activities.getLength() > 0) { mBehavior = Behavior.ACTIVITY; for (int i = 0; i < activities.getLength(); i++) mAllowedActivities.add(XmlUtil.getText(activities.item(i))); } } /* Notification */ Element notification = XmlUtil.getTag(root, "notification", null); if (notification != null) { /* By default, system, unless "activity" is specified */ mSystemNotification = !"activity".equals(notification.getAttribute("type")); /* The notification can be closed unless closeable is set to a non "true" value */ mNotiticationCloseable = XmlUtil.getBooleanAttribute(notification, "closeable", true); /* The notification has a content icon unless icon attribute set to a non "true" value. */ mNotificationIcon = XmlUtil.getBooleanAttribute(notification, "icon", true); /* Sound and vibration */ mNotificationSound = XmlUtil.getBooleanAttribute(notification, "sound", false); mNotificationVibrate = XmlUtil.getBooleanAttribute(notification, "vibrate", false); /* Parse texts */ mNotificationTitle = XmlUtil.getTagText(notification, "title", null); mNotificationMessage = XmlUtil.getTagText(notification, "message", null); /* Get image data, we decode the bitmap in a lazy way */ mNotificationImageString = XmlUtil.getTagText(notification, "image", null); /* Options */ String options = XmlUtil.getTagText(notification, "options", null); if (options != null) { JSONObject jOptions = new JSONObject(options); mNotificationBigText = jOptions.optString("bigText", null); mNotificationBigPicture = jOptions.optString("bigPicture", null); } } }
From source file:eu.elf.license.LicenseParser.java
/** * Creates LicenseParamEnum object/* w ww. j a v a 2s. c o m*/ * * @param parameterElement * @param parameterClass - parameter class (predefinedParameter || precalculatedParameter || referencedParameter || resultParameter || configurationParameter) * @return */ private static LicenseParamEnum createLicenseParamEnum(Element parameterElement, String parameterClass) { Boolean multiAttributeValue = false; LicenseParamEnum lpEnum = new LicenseParamEnum(); lpEnum.setParameterClass(parameterClass); NamedNodeMap parameterElementAttributeMap = parameterElement.getAttributes(); for (int i = 0; i < parameterElementAttributeMap.getLength(); i++) { Attr attrs = (Attr) parameterElementAttributeMap.item(i); if (attrs.getNodeName().equals("name")) { lpEnum.setName(attrs.getNodeValue()); } if (attrs.getNodeName().equals("multi")) { if (attrs.getNodeValue().equals("true")) { multiAttributeValue = true; } else { multiAttributeValue = false; } } } lpEnum.setMulti(multiAttributeValue); Element parameterTitleElement = (Element) parameterElement .getElementsByTagNameNS("http://www.conterra.de/xcpf/1.1", "title").item(0); if (parameterTitleElement != null) { lpEnum.setTitle(parameterTitleElement.getTextContent()); } NodeList valueElementList = parameterElement.getElementsByTagNameNS("http://www.conterra.de/xcpf/1.1", "value"); for (int j = 0; j < valueElementList.getLength(); j++) { Element valueElement = (Element) valueElementList.item(j); NamedNodeMap valueElementAttributeMap = valueElement.getAttributes(); for (int k = 0; k < valueElementAttributeMap.getLength(); k++) { Attr attrs = (Attr) valueElementAttributeMap.item(k); if (attrs.getNodeName().equals("selected")) { if (attrs.getNodeValue().equals("true")) { lpEnum.setDefaultValue(valueElement.getTextContent()); lpEnum.addSelection(valueElement.getTextContent()); } } } lpEnum.addOption(valueElement.getTextContent()); } return lpEnum; }
From source file:es.gob.afirma.signers.ooxml.be.fedict.eid.applet.service.signer.AbstractXmlSignatureService.java
@Override public byte[] postSign(final byte[] signedXML, final List<X509Certificate> signingCertificateChain, final String signatureId, final byte[] signatureValue) throws ParserConfigurationException, SAXException, IOException, TransformerException { // Load the signature DOM document. final Document document = loadDocument(new ByteArrayInputStream(signedXML)); // Locate the correct ds:Signature node. final Element nsElement = document.createElement("ns"); //$NON-NLS-1$ nsElement.setAttributeNS(Constants.NamespaceSpecNS, "xmlns:ds", Constants.SignatureSpecNS); //$NON-NLS-1$ final Element signatureElement = (Element) XPathAPI.selectSingleNode(document, "//ds:Signature[@Id='" + signatureId + "']", nsElement); //$NON-NLS-1$ //$NON-NLS-2$ if (null == signatureElement) { throw new IllegalArgumentException("ds:Signature not found for @Id: " + signatureId); //$NON-NLS-1$ }//from w w w . ja va 2s . co m // Insert signature value into the ds:SignatureValue element final NodeList signatureValueNodeList = signatureElement .getElementsByTagNameNS(javax.xml.crypto.dsig.XMLSignature.XMLNS, "SignatureValue"); //$NON-NLS-1$ final Element signatureValueElement = (Element) signatureValueNodeList.item(0); signatureValueElement.setTextContent(Base64.encode(signatureValue)); // TODO: Cambiar a OOXMLSignedDocumentOutputStream final ByteArrayOutputStream signedDocumentOutputStream = new ByteArrayOutputStream(); writeDocument(document, signedDocumentOutputStream); return signedDocumentOutputStream.toByteArray(); }
From source file:manchester.synbiochem.datacapture.SeekConnector.java
public String getInstitutionName() { try {/* ww w .j a v a 2s. c o m*/ Element d = get("/institutions/" + institution + ".xml").getDocumentElement(); return d.getElementsByTagNameNS(DC, "title").item(0).getTextContent(); } catch (IOException | SAXException | ParserConfigurationException e) { log.error("unexpected problem when fetching institution info", e); return institution + " (unsafe)"; } }
From source file:org.springjutsu.validation.namespace.ValidationEntityDefinitionParser.java
/** * Do actual parsing./* w w w .j a v a 2 s . c om*/ * Since rules may be nested, delegate to {@link #parseNestedRules(Element, Class)} * where necessary. */ public BeanDefinition parse(Element entityNode, ParserContext parserContext) { RootBeanDefinition entityDefinition = new RootBeanDefinition(ValidationEntity.class); String className = entityNode.getAttribute("class"); Class<?> modelClass; try { modelClass = Class.forName(className); } catch (ClassNotFoundException cnfe) { throw new ValidationParseException("Class " + className + " does not exist as a model class."); } List<String> excludePaths = new ArrayList<String>(); NodeList excludes = entityNode.getElementsByTagNameNS(entityNode.getNamespaceURI(), "recursion-exclude"); for (int excludeNbr = 0; excludeNbr < excludes.getLength(); excludeNbr++) { Element excludeNode = (Element) excludes.item(excludeNbr); String path = excludeNode.getAttribute("propertyName"); if (path.contains(".")) { throw new ValidationParseException("Invalid recursion-exclude property name \"" + path + "\" Exclude paths should not be nested fields."); } else { excludePaths.add(path); } } List<String> includePaths = new ArrayList<String>(); NodeList includes = entityNode.getElementsByTagNameNS(entityNode.getNamespaceURI(), "recursion-include"); for (int includeNbr = 0; includeNbr < includes.getLength(); includeNbr++) { Element includeNode = (Element) includes.item(includeNbr); String path = includeNode.getAttribute("propertyName"); if (path.contains(".")) { throw new ValidationParseException("Invalid recursion-include property name \"" + path + "\" Include paths should not be nested fields."); } else { includePaths.add(path); } } ValidationStructure validationStructure = parseNestedValidation(entityNode, modelClass); List<ValidationTemplate> templates = new ArrayList<ValidationTemplate>(); NodeList templateNodes = entityNode.getElementsByTagNameNS(entityNode.getNamespaceURI(), "template"); for (int templateNbr = 0; templateNbr < templateNodes.getLength(); templateNbr++) { Element templateNode = (Element) templateNodes.item(templateNbr); String templateName = templateNode.getAttribute("name"); ValidationStructure templateValidation = parseNestedValidation(templateNode, modelClass); ValidationTemplate template = new ValidationTemplate(templateName, modelClass); template.setRules(templateValidation.rules); template.setTemplateReferences(templateValidation.refs); template.setValidationContexts(templateValidation.contexts); templates.add(template); } entityDefinition.getPropertyValues().add("rules", validationStructure.rules); entityDefinition.getPropertyValues().add("templateReferences", validationStructure.refs); entityDefinition.getPropertyValues().add("validationContexts", validationStructure.contexts); entityDefinition.getPropertyValues().add("validationTemplates", templates); entityDefinition.getPropertyValues().add("validationClass", modelClass); entityDefinition.getPropertyValues().add("includedPaths", includePaths); entityDefinition.getPropertyValues().add("excludedPaths", excludePaths); String entityName = parserContext.getReaderContext().registerWithGeneratedName(entityDefinition); parserContext.registerComponent(new BeanComponentDefinition(entityDefinition, entityName)); return null; }
From source file:manchester.synbiochem.datacapture.SeekConnector.java
protected List<User> getUserList() throws SAXException, IOException, ParserConfigurationException { Document d = get("/people.xml?page=all"); Element items = (Element) d.getDocumentElement().getElementsByTagNameNS(SEEK, "items").item(0); NodeList personElements = items.getElementsByTagNameNS(SEEK, "person"); List<User> users = new ArrayList<>(); for (int i = 0; i < personElements.getLength(); i++) users.add(new User(personElements.item(i))); sort(users, userComparator);//from w w w .java2 s .c o m return users; }