List of usage examples for org.w3c.dom Element getNodeName
public String getNodeName();
From source file:com.sdl.odata.unmarshaller.atom.AtomLinkUnmarshaller.java
@Override protected String getToEntityId(ODataRequestContext requestContext) throws ODataUnmarshallingException { // The body is expected to contain a single entity reference // See OData Atom XML specification chapter 13 String bodyText;/*from w w w.j a va2s.c o m*/ try { bodyText = requestContext.getRequest().getBodyText(StandardCharsets.UTF_8.name()); } catch (UnsupportedEncodingException e) { throw new ODataSystemException("UTF-8 is not supported", e); } Document document = parseXML(bodyText); Element rootElement = document.getDocumentElement(); if (!rootElement.getNodeName().equals(REF)) { throw new ODataUnmarshallingException("A " + requestContext.getRequest().getMethod() + " request to an entity reference URI must contain a single entity reference in the body," + " but something else was found instead: " + rootElement.getNodeName()); } String idAttr = rootElement.getAttribute(ID); if (isNullOrEmpty(idAttr)) { throw new ODataUnmarshallingException("The <metadata:ref> element in the body has no 'id' attribute," + " or the attribute is empty. The element must have an 'id' attribute that refers" + " to the entity to link to."); } return idAttr; }
From source file:com.mtgi.analytics.aop.config.v11.BtConfigBeanDefinitionParser.java
public BeanDefinition parse(Element element, ParserContext parserContext) { CompositeComponentDefinition component = new CompositeComponentDefinition(element.getNodeName(), parserContext.extractSource(element)); parserContext.pushContainingComponent(component); try {//from w w w .j a v a 2s .com NodeList children = element.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { Node node = children.item(i); if (node.getNodeType() == Node.ELEMENT_NODE) parserContext.getDelegate().parseCustomElement((Element) node, null); } //no actual bean generated for bt:config. return null; } finally { parserContext.popAndRegisterContainingComponent(); } }
From source file:org.apache.servicemix.quartz.QuartzSpringTest.java
public void test() throws Exception { Receiver r1 = (Receiver) getBean("receiver1"); Receiver r2 = (Receiver) getBean("receiver2"); Receiver r3 = (Receiver) getBean("receiver3"); r1.getMessageList().assertMessagesReceived(1); r2.getMessageList().assertMessagesReceived(1); r3.getMessageList().assertMessagesReceived(1); NormalizedMessage nm = (NormalizedMessage) r3.getMessageList().flushMessages().get(0); Element e = new SourceTransformer().toDOMElement(nm); log.info(new SourceTransformer().contentToString(nm)); assertEquals("hello", e.getNodeName()); }
From source file:com.nexmo.client.verify.endpoints.VerifyEndpoint.java
protected VerifyResult parseVerifyResponse(String response) throws NexmoResponseParseException { Document doc = xmlParser.parseXml(response); Element root = doc.getDocumentElement(); if (!"verify_response".equals(root.getNodeName())) throw new NexmoResponseParseException("No valid response found [ " + response + "] "); return SharedParsers.parseVerifyResponseXmlNode(root); }
From source file:org.cbio.portal.pipelines.foundation.FoundationFileTasklet.java
/** * Extract the case data from source xml file by root tag * @param xmlFile/*from w w w. j a v a 2s .co m*/ * @return * @throws JAXBException * @throws IOException * @throws ParserConfigurationException * @throws SAXException */ private List<CaseType> extractFileCaseData(File xmlFile) throws JAXBException, IOException, ParserConfigurationException, SAXException { List<CaseType> newCases = new ArrayList(); // get the document root and determine how to unmarshal document Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(xmlFile); Element root = document.getDocumentElement(); if (root.getNodeName().equals("ClientCaseInfo")) { // unmarshal document with root tag = ClientCaseInfo JAXBContext context = JAXBContext.newInstance(ClientCaseInfoType.class); Unmarshaller jaxbUnmarshaller = context.createUnmarshaller(); ClientCaseInfoType cci = (ClientCaseInfoType) jaxbUnmarshaller.unmarshal(root); newCases.addAll(cci.getCases().getCase()); } else { // unmarshal document with root tag = ResultsReport JAXBContext context = JAXBContext.newInstance(ResultsReportType.class); Unmarshaller jaxbUnmarshaller = context.createUnmarshaller(); ResultsReportType rrt = (ResultsReportType) jaxbUnmarshaller.unmarshal(root); newCases.add(new CaseType(rrt.getVariantReport())); } return newCases; }
From source file:ar.com.zauber.commons.web.transformation.sanitizing.impl.AbstractElementNodeSanitizer.java
/** * Recursive tree traversal/*from w ww.j av a 2s.c om*/ * @param node * @param invalidElements */ private void sanitizeNode(final Node node, final List<Element> invalidElements) { if (node.getNodeType() == Node.ELEMENT_NODE) { final Element element = (Element) node; if (!tagSecurityStrategy.isTagAllowed(element.getNodeName())) { invalidElements.add(element); return; } else { final NamedNodeMap attributes = node.getAttributes(); if (attributes.getLength() > 0) { final List<Attr> invalidAttributes = new ArrayList<Attr>(); for (int i = 0; i < attributes.getLength(); ++i) { final Attr attribute = (Attr) attributes.item(i); if (!tagSecurityStrategy.isAttributeAllowedForTag(attribute.getNodeName(), element.getNodeName()) || !tagSecurityStrategy.isAttributeValueValidForTag(attribute.getNodeValue(), attribute.getNodeName(), element.getNodeName())) { invalidAttributes.add(attribute); } } processInvalidElementAttributes(element, invalidAttributes); } } } final NodeList children = node.getChildNodes(); for (int i = 0; i < children.getLength(); ++i) { sanitizeNode(children.item(i), invalidElements); } }
From source file:com.nexmo.client.verify.endpoints.VerifyCheckMethod.java
private CheckResult parseCheckResponse(String response) throws NexmoResponseParseException { Document doc = xmlParser.parseXml(response); Element root = doc.getDocumentElement(); if (!"verify_response".equals(root.getNodeName())) throw new NexmoResponseParseException("No valid response found [ " + response + "] "); String eventId = null;// w w w.j a v a2 s . co m int status = -1; float price = -1; String currency = null; String errorText = null; NodeList fields = root.getChildNodes(); for (int i = 0; i < fields.getLength(); i++) { Node node = fields.item(i); if (node.getNodeType() != Node.ELEMENT_NODE) continue; String name = node.getNodeName(); if ("event_id".equals(name)) { eventId = XmlUtil.stringValue(node); } else if ("status".equals(name)) { String str = XmlUtil.stringValue(node); try { if (str != null) status = Integer.parseInt(str); } catch (NumberFormatException e) { log.error("xml parser .. invalid value in <status> node [ " + str + " ] "); status = BaseResult.STATUS_INTERNAL_ERROR; } } else if ("price".equals(name)) { String str = XmlUtil.stringValue(node); try { if (str != null) price = Float.parseFloat(str); } catch (NumberFormatException e) { log.error("xml parser .. invalid value in <price> node [ " + str + " ] "); } } else if ("currency".equals(name)) { currency = XmlUtil.stringValue(node); } else if ("error_text".equals(name)) { errorText = XmlUtil.stringValue(node); } } if (status == -1) throw new NexmoResponseParseException("Xml Parser - did not find a <status> node"); // Is this a temporary error ? boolean temporaryError = (status == BaseResult.STATUS_THROTTLED || status == BaseResult.STATUS_INTERNAL_ERROR); return new CheckResult(status, eventId, price, currency, errorText, temporaryError); }
From source file:com.sqewd.os.maracache.core.Config.java
private void setParams(ConfigParams node, Element elm) { for (int ii = 0; ii < elm.getChildNodes().getLength(); ii++) { Node n = elm.getChildNodes().item(ii); if (n.getNodeType() == Node.ELEMENT_NODE) { Element e = (Element) n; if (e.getNodeName().compareToIgnoreCase(ConfigParams.NODE_VALUE_NAME) == 0) { String name = e.getAttribute(ConfigParams.NODE_ATTR_NAME); String value = e.getAttribute(ConfigParams.NODE_ATTR_VALUE); if (!StringUtils.isEmpty(name) && !StringUtils.isEmpty(value)) { node.addParam(name, value); }/*from w w w . j a v a 2s. c o m*/ } } } }
From source file:com.opengamma.web.bundle.BundleParser.java
private boolean isBundleElement(Element element) { if (element.getNodeName().equals(BUNDLE_ELEMENT)) { return true; }/*from w ww . jav a 2s . co m*/ throw new OpenGammaRuntimeException("parsing bundle XML : element not a bundle"); }
From source file:fi.capeismi.fish.uistelupaivakirja.model.WeatherInfo.java
private void parseXML(InputStream in) throws ParserConfigurationException, IOException, SAXException { DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); Document dom = builder.parse(in); Element root = dom.getDocumentElement(); NodeList conditions = root.getElementsByTagName("current_conditions"); if (conditions.getLength() == 1) { conditions = conditions.item(0).getChildNodes(); }//w ww . ja v a 2s .c o m for (int loop = 0; loop < conditions.getLength(); loop++) { Element condition = (Element) conditions.item(loop); String tagname = condition.getNodeName(); String value = condition.getAttribute("data"); if (tagname.equalsIgnoreCase("temp_c")) { m_event.setAirTemp(value); } else if (tagname.equalsIgnoreCase("condition")) { int clouds = parseCondition(value); if (clouds > 0) { m_event.setClouds(clouds); } } else if (tagname.equalsIgnoreCase("wind_condition")) { int wind = parseWindSpeed(value); int direction = parseWindDirection(value); if (wind > 0) { m_event.setWindSpeed(wind); } if (direction > 0) { m_event.setWindDirection(direction); } } } }