javax.xml.soap.Node Java Examples
The following examples show how to use
javax.xml.soap.Node.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: InsurabilityHandler.java From freehealth-connector with GNU Affero General Public License v3.0 | 6 votes |
private static void initMessageID(SOAPMessage msg) throws SOAPException { SOAPPart part = msg.getSOAPPart(); if (part != null) { SOAPEnvelope soapEnvelope = part.getEnvelope(); if (soapEnvelope != null) { SOAPHeader header = soapEnvelope.getHeader(); if (header != null && header.getChildElements().hasNext()) { Node elementsResponseHeader = (Node) header.getChildElements().next(); if (elementsResponseHeader != null && elementsResponseHeader.getLocalName() != null && elementsResponseHeader.getLocalName().equals("MessageID")) { NodeList elementsheader = elementsResponseHeader.getChildNodes(); org.w3c.dom.Node element = elementsheader.item(0); messageId = element.getNodeValue(); LOG.info("MyCareNet returned a response with messageId: " + messageId); } } } } }
Example #2
Source File: EntityRepository.java From JavaMainRepo with Apache License 2.0 | 6 votes |
public ArrayList<T> load() throws ParserConfigurationException, SAXException, IOException { ArrayList<T> entities = new ArrayList<T>(); File fXmlFile = new File(this.xmlFilename); DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); Document doc = dBuilder.parse(fXmlFile); doc.getDocumentElement().normalize(); NodeList nodeList = doc.getElementsByTagName(this.entityTag); for (int i = 0; i < nodeList.getLength(); i++) { org.w3c.dom.Node node = nodeList.item(i); if (node.getNodeType() == Node.ELEMENT_NODE) { Element element = (Element) node; entities.add(getEntityFromXmlElement(element)); } } return entities; }
Example #3
Source File: EntityRepository.java From JavaMainRepo with Apache License 2.0 | 6 votes |
public ArrayList<T> load() throws Exception { ArrayList<T> entities = new ArrayList<T>(); File fXmlFile = new File(this.xmlFilename); DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); Document doc = dBuilder.parse(fXmlFile); doc.getDocumentElement().normalize(); NodeList nodeList = doc.getElementsByTagName(this.entityTag); for (int i = 0; i < nodeList.getLength(); i++) { org.w3c.dom.Node node = nodeList.item(i); if (node.getNodeType() == Node.ELEMENT_NODE) { Element element = (Element) node; entities.add(getEntityFromXmlElement(element)); } } return entities; }
Example #4
Source File: EntityRepository.java From JavaMainRepo with Apache License 2.0 | 6 votes |
public ArrayList<T> load() throws Exception { ArrayList<T> entities = new ArrayList<T>(); File fXmlFile = new File(this.xmlFilename); DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); Document doc = dBuilder.parse(fXmlFile); doc.getDocumentElement().normalize(); NodeList nodeList = doc.getElementsByTagName(this.entityTag); for (int i = 0; i < nodeList.getLength(); i++) { org.w3c.dom.Node node = nodeList.item(i); if (node.getNodeType() == Node.ELEMENT_NODE) { Element element = (Element) node; entities.add(getEntityFromXmlElement(element)); } } return entities; }
Example #5
Source File: EntityRepository.java From JavaMainRepo with Apache License 2.0 | 6 votes |
public ArrayList<T> load() throws Exception { ArrayList<T> entities = new ArrayList<T>(); File fXmlFile = new File(this.xmlFilename); DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); Document doc = dBuilder.parse(fXmlFile); doc.getDocumentElement().normalize(); NodeList nodeList = doc.getElementsByTagName(this.entityTag); for (int i = 0; i < nodeList.getLength(); i++) { org.w3c.dom.Node node = nodeList.item(i); if (node.getNodeType() == Node.ELEMENT_NODE) { Element element = (Element) node; entities.add(getEntityFromXmlElement(element)); } } return entities; }
Example #6
Source File: EntityRepository.java From JavaMainRepo with Apache License 2.0 | 6 votes |
public ArrayList<T> load() throws Exception { ArrayList<T> entities = new ArrayList<T>(); File fXmlFile = new File(this.xmlFilename); DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); Document doc = dBuilder.parse(fXmlFile); doc.getDocumentElement().normalize(); NodeList nodeList = doc.getElementsByTagName(this.entityTag); for (int i = 0; i < nodeList.getLength(); i++) { org.w3c.dom.Node node = nodeList.item(i); if (node.getNodeType() == Node.ELEMENT_NODE) { Element element = (Element) node; entities.add(getEntityFromXmlElement(element)); } } return entities; }
Example #7
Source File: EntityRepository.java From JavaMainRepo with Apache License 2.0 | 6 votes |
public ArrayList<T> load() throws ParserConfigurationException, SAXException, IOException { ArrayList<T> entities = new ArrayList<T>(); File fXmlFile = new File(this.xmlFilename); DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); Document doc = (Document) dBuilder.parse(fXmlFile); doc.getDocumentElement().normalize(); NodeList nodeList = doc.getElementsByTagName(Constants.XML_TAGS.ANIMAL); for (int i = 0; i < nodeList.getLength(); i++) { Node node = (Node) nodeList.item(i); if (node.getNodeType() == Node.ELEMENT_NODE) { Element element = (Element) node; entities.add(getEntityFromXmlElement(element)); } } return entities; }
Example #8
Source File: SoapRequestParserTest.java From development with Apache License 2.0 | 6 votes |
@Test public void parseApiVersion_ctmg_1_8() throws Exception { // given SOAPPart part = mock(SOAPPart.class); SOAPEnvelope envelope = mock(SOAPEnvelope.class); SOAPHeader soapHeader = mock(SOAPHeader.class); List<Node> version = new ArrayList<Node>(); Node node = mock(Node.class); doReturn("testVersion").when(node).getValue(); version.add(node); Iterator<?> it = version.iterator(); doReturn(it).when(soapHeader).extractHeaderElements( eq("ctmg.service.version")); doReturn(soapHeader).when(envelope).getHeader(); doReturn(envelope).when(part).getEnvelope(); doReturn(part).when(message).getSOAPPart(); // when String result = SoapRequestParser.parseApiVersion(context); // then assertEquals("testVersion", result); }
Example #9
Source File: SoapRequestParserTest.java From development with Apache License 2.0 | 6 votes |
@Test public void parseApiVersion_cm_1_8() throws Exception { // given SOAPPart part = mock(SOAPPart.class); SOAPEnvelope envelope = mock(SOAPEnvelope.class); SOAPHeader soapHeader = mock(SOAPHeader.class); List<Node> version = new ArrayList<Node>(); Node node = mock(Node.class); doReturn("testVersion").when(node).getValue(); version.add(node); Iterator<?> it = version.iterator(); doReturn(it).when(soapHeader).extractHeaderElements( eq("cm.service.version")); doReturn(soapHeader).when(envelope).getHeader(); doReturn(envelope).when(part).getEnvelope(); doReturn(part).when(message).getSOAPPart(); // when String result = SoapRequestParser.parseApiVersion(context); // then assertEquals("testVersion", result); }
Example #10
Source File: EntityRepository.java From JavaMainRepo with Apache License 2.0 | 6 votes |
public ArrayList<T> load() throws ParserConfigurationException, SAXException, IOException { ArrayList<T> entities = new ArrayList<T>(); File fXmlFile = new File(this.xmlFilename); DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); Document doc = dBuilder.parse(fXmlFile); doc.getDocumentElement().normalize(); NodeList nodeList = doc.getElementsByTagName(this.entityTag); for (int i = 0; i < nodeList.getLength(); i++) { org.w3c.dom.Node node = nodeList.item(i); if (node.getNodeType() == Node.ELEMENT_NODE) { Element element = (Element) node; entities.add(getEntityFromXmlElement(element)); } } return entities; }
Example #11
Source File: EntityRepository.java From JavaMainRepo with Apache License 2.0 | 6 votes |
public ArrayList<T> load() throws ParserConfigurationException, SAXException, IOException { ArrayList<T> entities = new ArrayList<T>(); File fXmlFile = new File(this.xmlFilename); DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); Document doc = dBuilder.parse(fXmlFile); doc.getDocumentElement().normalize(); NodeList nodeList = doc.getElementsByTagName(this.entityTag); for (int i = 0; i < nodeList.getLength(); i++) { org.w3c.dom.Node node = nodeList.item(i); if (node.getNodeType() == Node.ELEMENT_NODE) { Element element = (Element) node; entities.add(getEntityFromXmlElement(element)); } } return entities; }
Example #12
Source File: EntityRepository.java From JavaMainRepo with Apache License 2.0 | 6 votes |
public ArrayList<T> load() throws ParserConfigurationException, SAXException, IOException { ArrayList<T> entities = new ArrayList<T>(); File fXmlFile = new File(this.xmlFilename); DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); Document doc = dBuilder.parse(fXmlFile); doc.getDocumentElement().normalize(); NodeList nodeList = doc.getElementsByTagName(this.entityTag); for (int i = 0; i < nodeList.getLength(); i++) { org.w3c.dom.Node node = nodeList.item(i); if (node.getNodeType() == Node.ELEMENT_NODE) { Element element = (Element) node; entities.add(getEntityFromXmlElement(element)); } } return entities; }
Example #13
Source File: SOAPHandlerInterceptor.java From cxf with Apache License 2.0 | 6 votes |
protected QName getOpQName(Exchange ex, Object data) { SOAPMessageContextImpl sm = (SOAPMessageContextImpl)data; try { SOAPMessage msg = sm.getMessage(); if (msg == null) { return null; } SOAPBody body = SAAJUtils.getBody(msg); if (body == null) { return null; } org.w3c.dom.Node nd = body.getFirstChild(); while (nd != null && !(nd instanceof org.w3c.dom.Element)) { nd = nd.getNextSibling(); } if (nd != null) { return new QName(nd.getNamespaceURI(), nd.getLocalName()); } } catch (SOAPException e) { //ignore, nothing we can do } return null; }
Example #14
Source File: InsurabilityHandler.java From freehealth-connector with GNU Affero General Public License v3.0 | 6 votes |
private static void initMessageID(SOAPMessage msg) throws SOAPException { SOAPPart part = msg.getSOAPPart(); if (part != null) { SOAPEnvelope soapEnvelope = part.getEnvelope(); if (soapEnvelope != null) { SOAPHeader header = soapEnvelope.getHeader(); if (header != null && header.getChildElements().hasNext()) { Node elementsResponseHeader = (Node) header.getChildElements().next(); if (elementsResponseHeader != null && elementsResponseHeader.getLocalName() != null && elementsResponseHeader.getLocalName().equals("MessageID")) { NodeList elementsheader = elementsResponseHeader.getChildNodes(); org.w3c.dom.Node element = elementsheader.item(0); messageId = element.getNodeValue(); LOG.info("MyCareNet returned a response with messageId: " + messageId); } } } } }
Example #15
Source File: LoggingHandler.java From freehealth-connector with GNU Affero General Public License v3.0 | 6 votes |
private void getMessageID(SOAPMessage msg) throws SOAPException { SOAPHeader header = msg.getSOAPHeader(); if (header != null && header.getChildElements().hasNext()) { Node elementsResponseHeader = (Node)header.getChildElements().next(); NodeList elementsheader = elementsResponseHeader.getChildNodes(); for(int i = 0; i < elementsheader.getLength(); ++i) { org.w3c.dom.Node element = elementsheader.item(i); if (element.getLocalName() != null && element.getLocalName().equals("MessageID")) { LOG.info("The message id of the response: " + element.getNodeValue()); break; } } } }
Example #16
Source File: InsurabilityHandler.java From freehealth-connector with GNU Affero General Public License v3.0 | 6 votes |
private static void initMessageID(SOAPMessage msg) throws SOAPException { SOAPPart part = msg.getSOAPPart(); if (part != null) { SOAPEnvelope soapEnvelope = part.getEnvelope(); if (soapEnvelope != null) { SOAPHeader header = soapEnvelope.getHeader(); if (header != null && header.getChildElements().hasNext()) { Node elementsResponseHeader = (Node) header.getChildElements().next(); if (elementsResponseHeader != null && elementsResponseHeader.getLocalName() != null && elementsResponseHeader.getLocalName().equals("MessageID")) { NodeList elementsheader = elementsResponseHeader.getChildNodes(); org.w3c.dom.Node element = elementsheader.item(0); messageId = element.getNodeValue(); LOG.info("MyCareNet returned a response with messageId: " + messageId); } } } } }
Example #17
Source File: LoggingHandler.java From freehealth-connector with GNU Affero General Public License v3.0 | 6 votes |
private void getMessageID(SOAPMessage msg) throws SOAPException { SOAPHeader header = msg.getSOAPHeader(); if (header != null && header.getChildElements().hasNext()) { Node elementsResponseHeader = (Node)header.getChildElements().next(); NodeList elementsheader = elementsResponseHeader.getChildNodes(); for(int i = 0; i < elementsheader.getLength(); ++i) { org.w3c.dom.Node element = elementsheader.item(i); if (element.getLocalName() != null && element.getLocalName().equals("MessageID")) { LOG.info("The message id of the response: " + element.getNodeValue()); break; } } } }
Example #18
Source File: InsurabilityHandler.java From freehealth-connector with GNU Affero General Public License v3.0 | 6 votes |
private static void initMessageID(SOAPMessage msg) throws SOAPException { SOAPPart part = msg.getSOAPPart(); if (part != null) { SOAPEnvelope soapEnvelope = part.getEnvelope(); if (soapEnvelope != null) { SOAPHeader header = soapEnvelope.getHeader(); if (header != null && header.getChildElements().hasNext()) { Node elementsResponseHeader = (Node)header.getChildElements().next(); if (elementsResponseHeader != null && elementsResponseHeader.getLocalName() != null && elementsResponseHeader.getLocalName().equals("MessageID")) { NodeList elementsheader = elementsResponseHeader.getChildNodes(); org.w3c.dom.Node element = elementsheader.item(0); messageId = element.getNodeValue(); LOG.info("MyCareNet returned a response with messageId: " + messageId); } } } } }
Example #19
Source File: ConsumerGateway.java From xroad-rest-gateway with European Union Public License 1.1 | 5 votes |
@Override protected String deserializeResponseData(Node responseNode, SOAPMessage message) throws SOAPException { // Remove namespace if it's required handleNamespace(responseNode); // If message has attachments, return the first attachment if (message.countAttachments() > 0) { logger.debug("SOAP attachment detected. Use attachment as response data."); return SOAPHelper.toString((AttachmentPart) message.getAttachments().next()); } // Convert response to string return SOAPHelper.toString(responseNode); }
Example #20
Source File: ProviderGateway.java From xroad-rest-gateway with European Union Public License 1.1 | 5 votes |
@Override protected Map deserializeRequest(Node requestNode, SOAPMessage message) throws SOAPException { if (requestNode == null) { logger.warn("\"requestNode\" is null. Null is returned."); return null; } // Convert all the elements under request to key - value list pairs. // Each key can have multiple values Map map = SOAPHelper.nodesToMultiMap(requestNode.getChildNodes()); // If message has attachments, use the first attachment as // request body processAttachment(map, message); return map; }
Example #21
Source File: ProviderGateway.java From xroad-rest-gateway with European Union Public License 1.1 | 5 votes |
@Override protected Map deserializeRequest(Node requestNode, SOAPMessage message) throws SOAPException { if (requestNode == null) { logger.warn("\"requestNode\" is null. Null is returned."); return null; } Map<String, String> nodes = SOAPHelper.nodesToMap(requestNode.getChildNodes()); // Decrypt session key using the private key Decrypter symmetricDecrypter = RESTGatewayUtil.getSymmetricDecrypter(this.asymmetricDecrypter, nodes.get(Constants.PARAM_KEY), nodes.get(Constants.PARAM_IV)); // Decrypt the data String decrypted = symmetricDecrypter.decrypt(nodes.get(Constants.PARAM_ENCRYPTED)); // Convert decrypted data to SOAP element SOAPElement soapData = SOAPHelper.xmlStrToSOAPElement(decrypted); // Convert all the elements under request to key - value list pairs. // Each key can have multiple values Map map = SOAPHelper.nodesToMultiMap(soapData.getChildNodes()); // If message has attachments, use the first attachment as // request body processAttachment(map, message); // If the message has attachment, it has to be decrypted too if (map.containsKey(Constants.PARAM_REQUEST_BODY)) { // Get attachment value by fixed parameter name. The map // contains key - value list so we must get the whole list. List<String> values = (List<String>) map.get(Constants.PARAM_REQUEST_BODY); // Only the first attachment is handled String encryptedValue = values.get(0); // Create new list that's added to the results List<String> newValues = new ArrayList<>(); // Add decrypted attachment to the new list newValues.add(symmetricDecrypter.decrypt(encryptedValue)); // Replace the old value with the new one map.put(Constants.PARAM_REQUEST_BODY, newValues); } return map; }
Example #22
Source File: EmployeeRepository.java From JavaMainRepo with Apache License 2.0 | 5 votes |
public ArrayList<Employee> load() throws ParserConfigurationException, SAXException, IOException { ArrayList<Employee> employees = new ArrayList<Employee>(); File fXmlFile = new File(XML_FILENAME); DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); Document doc = dBuilder.parse(fXmlFile); doc.getDocumentElement().normalize(); NodeList nodeList = doc.getElementsByTagName(Constants.XML_TAGS.EMPLOYEE); for (int i = 0; i < nodeList.getLength(); i++) { org.w3c.dom.Node node = nodeList.item(i); if (node.getNodeType() == Node.ELEMENT_NODE) { Element element = (Element) node; String discriminant = element.getElementsByTagName(Constants.XML_TAGS.DISCRIMINANT).item(0) .getTextContent(); switch (discriminant) { case Constants.Employees.Caretaker: String name = element.getElementsByTagName("name").item(0).getTextContent(); BigDecimal salary = BigDecimal .valueOf(Double.valueOf(element.getElementsByTagName("salary").item(0).getTextContent())); long id = Long.valueOf(element.getElementsByTagName("id").item(0).getTextContent()); Employee caretaker = new Caretaker(name, id, salary); caretaker.decodeFromXml(element); employees.add(caretaker); break; default: break; } } } return employees; }
Example #23
Source File: ProviderGateway.java From xroad-rest-gateway with European Union Public License 1.1 | 5 votes |
protected void handleBody(ServiceResponse response, SOAPElement soapResponse, SOAPEnvelope envelope) throws SOAPException { SOAPElement responseElem = (SOAPElement) response.getResponseData(); if ("response".equals(responseElem.getLocalName())) { logger.debug("Additional \"response\" wrapper detected. Remove the wrapper."); for (int i = 0; i < responseElem.getChildNodes().getLength(); i++) { Node importNode = (Node) soapResponse.getOwnerDocument().importNode(responseElem.getChildNodes().item(i), true); soapResponse.appendChild(importNode); } } else { soapResponse.addChildElement((SOAPElement) response.getResponseData()); } }
Example #24
Source File: EmployeeRepository.java From JavaMainRepo with Apache License 2.0 | 5 votes |
public ArrayList<Employee> load() throws ParserConfigurationException, SAXException, IOException{ ArrayList<Employee> employees = new ArrayList<Employee>(); File fXmlFile = new File(XML_FILENAME); DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); Document doc = (Document) dBuilder.parse(fXmlFile); doc.getDocumentElement().normalize(); NodeList nodeList = doc.getElementsByTagName(Constants.XML_TAGS.EMPLOYEE); for (int i = 0; i < nodeList.getLength(); i++) { Node node = (Node) nodeList.item(i); if (node.getNodeType() == Node.ELEMENT_NODE) { Element element = (Element) node; String discriminant = element.getElementsByTagName(Constants.XML_TAGS.DISCRIMINANT).item(0).getTextContent(); switch (discriminant) { case Constants.Employee.Caretaker: Employee caretaker = new Caretaker(); caretaker.decodeFromXml(element); employees.add(caretaker); default: break; } } } return employees; }
Example #25
Source File: SOAPHandlerInterceptor.java From cxf with Apache License 2.0 | 5 votes |
@Override protected MessageContext createProtocolMessageContext(SoapMessage message) { SOAPMessageContextImpl sm = new SOAPMessageContextImpl(message); Exchange exch = message.getExchange(); setupBindingOperationInfo(exch, sm); SOAPMessage msg = sm.getMessage(); if (msg != null) { try { List<SOAPElement> params = new ArrayList<>(); message.put(MessageContext.REFERENCE_PARAMETERS, params); SOAPHeader head = SAAJUtils.getHeader(msg); if (head != null) { Iterator<Node> it = CastUtils.cast(head.getChildElements()); while (it != null && it.hasNext()) { Node nd = it.next(); if (nd instanceof SOAPElement) { SOAPElement el = (SOAPElement) nd; if (el.hasAttributeNS(Names.WSA_NAMESPACE_NAME, "IsReferenceParameter") && ("1".equals(el.getAttributeNS(Names.WSA_NAMESPACE_NAME, "IsReferenceParameter")) || Boolean.parseBoolean(el.getAttributeNS(Names.WSA_NAMESPACE_NAME, "IsReferenceParameter")))) { params.add(el); } } } } if (isRequestor(message) && msg.getSOAPPart().getEnvelope().getBody() != null && msg.getSOAPPart().getEnvelope().getBody().hasFault()) { return null; } } catch (SOAPException e) { throw new Fault(e); } } return sm; }
Example #26
Source File: InsurabilityHandler.java From freehealth-connector with GNU Affero General Public License v3.0 | 5 votes |
public boolean handleMessage(SOAPMessageContext c) { try { Boolean outboundProperty = (Boolean)c.get("javax.xml.ws.handler.message.outbound"); if (!outboundProperty.booleanValue()) { SOAPMessage msg = c.getMessage(); ByteArrayOutputStream out = new ByteArrayOutputStream(); msg.writeTo(out); Node elementsGetPrescriptionForExecutorResponse = (Node)msg.getSOAPBody().getChildElements().next(); NodeList elements = elementsGetPrescriptionForExecutorResponse.getChildNodes(); for(int i = 0; i < elements.getLength(); ++i) { org.w3c.dom.Node element = elements.item(i); if (element.getLocalName() != null && (element.getLocalName().equals("GetInsurabilityForPharmacistResponse") || element.getLocalName().equals("InsurabilityResponse"))) { initMessageID(msg); Transformer t = TransformerFactory.newInstance().newTransformer(); StringWriter sw = new StringWriter(); t.transform(new DOMSource(element), new StreamResult(sw)); insurability = sw.toString(); break; } } } } catch (Throwable var11) { LOG.warn("SOAPException when retrieving insurability the message", var11); } return true; }
Example #27
Source File: EmployeeRepository.java From JavaMainRepo with Apache License 2.0 | 5 votes |
public ArrayList<Employee> load() throws Exception { ArrayList<Employee> employees = new ArrayList<Employee>(); File fXmlFile = new File(XML_FILENAME); DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); Document doc = dBuilder.parse(fXmlFile); doc.getDocumentElement().normalize(); NodeList nodeList = doc.getElementsByTagName(Constants.XML_TAGS.EMPLOYEE); for (int i = 0; i < nodeList.getLength(); i++) { org.w3c.dom.Node node = nodeList.item(i); if (node.getNodeType() == Node.ELEMENT_NODE) { Element element = (Element) node; String discriminant = element.getElementsByTagName(Constants.XML_TAGS.DISCRIMINANT).item(0) .getTextContent(); switch (discriminant) { case Constants.Employees.Employee.Caretaker: EmployeeAbstractFactory caretakers = new CaretakerFactory(); Employee caretaker = (Caretaker) caretakers.getEmployee(Constants.Employees.Employee.Caretaker); caretaker.decodeFromXml(element); employees.add(caretaker); default: break; } } } return employees; }
Example #28
Source File: EmployeeRepository.java From JavaMainRepo with Apache License 2.0 | 5 votes |
public ArrayList<Employee> load() throws Exception { ArrayList<Employee> employees = new ArrayList<Employee>(); File fXmlFile = new File(XML_FILENAME); DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); Document doc = dBuilder.parse(fXmlFile); doc.getDocumentElement().normalize(); NodeList nodeList = doc.getElementsByTagName(Constants.XML_TAGS.EMPLOYEE); for (int i = 0; i < nodeList.getLength(); i++) { org.w3c.dom.Node node = nodeList.item(i); if (node.getNodeType() == Node.ELEMENT_NODE) { Element element = (Element) node; String discriminant = element.getElementsByTagName(Constants.XML_TAGS.DISCRIMINANT).item(0) .getTextContent(); switch (discriminant) { case Constants.Employees.Employee.Caretaker: EmployeeAbstractFactory caretakers = new CaretakerFactory(); Employee caretaker = (Caretaker) caretakers.getEmployee(Constants.Employees.Employee.Caretaker); caretaker.decodeFromXml(element); employees.add(caretaker); default: break; } } } return employees; }
Example #29
Source File: WebService.java From JVoiceXML with GNU Lesser General Public License v2.1 | 5 votes |
public final static String getElementValue(Node elem) { org.w3c.dom.Node kid; if (elem != null) { if (elem.hasChildNodes()) { for (kid = elem.getFirstChild(); kid != null; kid = kid.getNextSibling()) { if (kid.getNodeType() == Node.TEXT_NODE) { return kid.getNodeValue(); } } } } return ""; }
Example #30
Source File: SOAPConnectionImpl.java From JVoiceXML with GNU Lesser General Public License v2.1 | 5 votes |
public final static String getElementValue( Node elem ) { org.w3c.dom.Node kid; if( elem != null){ if (elem.hasChildNodes()){ for( kid = elem.getFirstChild(); kid != null; kid = kid.getNextSibling() ){ if( kid.getNodeType() == Node.TEXT_NODE ){ return kid.getNodeValue(); } } } } return ""; }