BowlerKernel
XmlFactory.java
Go to the documentation of this file.
1 package com.neuronrobotics.sdk.addons.kinematics.xml;
2 import java.io.IOException;
3 import java.io.InputStream;
4 
5 import javax.xml.parsers.DocumentBuilder;
6 import javax.xml.parsers.DocumentBuilderFactory;
7 import javax.xml.parsers.ParserConfigurationException;
8 
9 import org.w3c.dom.Document;
10 import org.w3c.dom.Element;
11 import org.w3c.dom.Node;
12 import org.w3c.dom.NodeList;
13 import org.xml.sax.SAXException;
14 
15 // TODO: Auto-generated Javadoc
19 public class XmlFactory {
20 
27  public static InputStream getDefaultConfigurationStream(String file) {
28  return XmlFactory.class.getResourceAsStream(file);
29  }
30 
37  public static Document getAllNodesDocument(InputStream config) {
38  //InputStream config = XmlFactory.getDefaultConfigurationStream("DyioServo.xml");
39  DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
40  DocumentBuilder dBuilder;
41  Document doc = null;
42  try {
43  dBuilder = dbFactory.newDocumentBuilder();
44  doc = dBuilder.parse(config);
45  doc.getDocumentElement().normalize();
46  } catch (ParserConfigurationException e) {
47  throw new RuntimeException(e);
48  } catch (SAXException e) {
49  throw new RuntimeException(e);
50  } catch (IOException e) {
51  throw new RuntimeException(e);
52  }
53  return doc;
54  }
55 
56 
64  public static NodeList getAllNodesFromTag(String sTag, InputStream config){
65  Document doc =getAllNodesDocument(config);
66  //Parsing XML File and store in LinkConfiguration
67  return doc.getElementsByTagName(sTag);
68  }
69 
77  public static String getTagValue(String sTag, Element eElement){
78 
79  NodeList nlList= eElement.getElementsByTagName(sTag).item(0).getChildNodes();
80  Node nValue = (Node) nlList.item(0);
81  // System.out.println("\t\t"+sTag+" = "+nValue.getNodeValue());
82  return nValue.getNodeValue();
83  }
84 
92  public static Double getTagValueDouble(String sTag, Element eElement){
93  NodeList nlList= eElement.getElementsByTagName(sTag).item(0).getChildNodes();
94  Node nValue = (Node) nlList.item(0);
95  // System.out.println("\t\t"+sTag+" = "+nValue.getNodeValue());
96  return Double.parseDouble(nValue.getNodeValue());
97  }
98 }
99 
static Double getTagValueDouble(String sTag, Element eElement)
Definition: XmlFactory.java:92
static String getTagValue(String sTag, Element eElement)
Definition: XmlFactory.java:77
static InputStream getDefaultConfigurationStream(String file)
Definition: XmlFactory.java:27
static Document getAllNodesDocument(InputStream config)
Definition: XmlFactory.java:37
static NodeList getAllNodesFromTag(String sTag, InputStream config)
Definition: XmlFactory.java:64