use of org.openhab.binding.insteonplm.internal.utils.Utils.ParsingException in project openhab1-addons by openhab.
the class FeatureTemplateLoader method s_makeHandlerEntry.
private static HandlerEntry s_makeHandlerEntry(Element e) throws ParsingException {
String handler = e.getTextContent();
if (handler == null) {
throw new ParsingException("Could not find Handler for: " + e.getTextContent());
}
NamedNodeMap attributes = e.getAttributes();
HashMap<String, String> params = new HashMap<String, String>();
for (int i = 0; i < attributes.getLength(); i++) {
Node n = attributes.item(i);
params.put(n.getNodeName(), n.getNodeValue());
}
return new HandlerEntry(handler, params);
}
use of org.openhab.binding.insteonplm.internal.utils.Utils.ParsingException in project openhab1-addons by openhab.
the class XMLMessageReader method s_readMessageDefinition.
private static Pair<String, Msg> s_readMessageDefinition(Element msg) throws FieldException, ParsingException {
int length = 0;
int hlength = 0;
LinkedHashMap<Field, Object> fieldMap = new LinkedHashMap<Field, Object>();
String dir = msg.getAttribute("direction");
String name = msg.getAttribute("name");
Msg.Direction direction = Msg.Direction.s_getDirectionFromString(dir);
if (msg.hasAttribute("length")) {
length = Integer.parseInt(msg.getAttribute("length"));
}
NodeList nodes = msg.getChildNodes();
int offset = 0;
for (int i = 0; i < nodes.getLength(); i++) {
Node node = nodes.item(i);
if (node.getNodeType() == Node.ELEMENT_NODE) {
if (node.getNodeName().equals("header")) {
int o = s_readHeaderElement((Element) node, fieldMap);
hlength = o;
// Increment the offset by the header length
offset += o;
} else {
Pair<Field, Object> field = s_readField((Element) node, offset);
fieldMap.put(field.getKey(), field.getValue());
// Increment the offset
offset += field.getKey().getType().getSize();
}
}
}
if (offset != length) {
throw new ParsingException("Actual msg length " + offset + " differs from given msg length " + length + "!");
}
if (length == 0) {
length = offset;
}
return new Pair<String, Msg>(name, s_createMsg(fieldMap, length, hlength, direction));
}
use of org.openhab.binding.insteonplm.internal.utils.Utils.ParsingException in project openhab1-addons by openhab.
the class XMLMessageReader method s_readMessageDefinitions.
/**
* Reads the message definitions from an xml file
*
* @param input input stream from which to read
* @return what was read from file: the map between clear text string and Msg objects
* @throws IOException couldn't read file etc
* @throws ParsingException something wrong with the file format
* @throws FieldException something wrong with the field definition
*/
public static HashMap<String, Msg> s_readMessageDefinitions(InputStream input) throws IOException, ParsingException, FieldException {
HashMap<String, Msg> messageMap = new HashMap<String, Msg>();
try {
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
// Parse it!
Document doc = dBuilder.parse(input);
doc.getDocumentElement().normalize();
Node root = doc.getDocumentElement();
NodeList nodes = root.getChildNodes();
for (int i = 0; i < nodes.getLength(); i++) {
Node node = nodes.item(i);
if (node.getNodeType() == Node.ELEMENT_NODE) {
if (node.getNodeName().equals("msg")) {
Pair<String, Msg> msgDef = s_readMessageDefinition((Element) node);
messageMap.put(msgDef.getKey(), msgDef.getValue());
}
}
}
} catch (SAXException e) {
throw new ParsingException("Failed to parse XML!", e);
} catch (ParserConfigurationException e) {
throw new ParsingException("Got parser config exception! ", e);
}
return messageMap;
}
use of org.openhab.binding.insteonplm.internal.utils.Utils.ParsingException in project openhab1-addons by openhab.
the class XMLMessageReader method s_readHeaderElement.
private static int s_readHeaderElement(Element header, LinkedHashMap<Field, Object> fields) throws ParsingException {
int offset = 0;
int headerLen = Integer.parseInt(header.getAttribute("length"));
NodeList nodes = header.getChildNodes();
for (int i = 0; i < nodes.getLength(); i++) {
Node node = nodes.item(i);
if (node.getNodeType() == Node.ELEMENT_NODE) {
Pair<Field, Object> definition = s_readField((Element) node, offset);
if (definition != null) {
offset += definition.getKey().getType().getSize();
fields.put(definition.getKey(), definition.getValue());
}
}
}
if (headerLen != offset) {
throw new ParsingException("Actual header length " + offset + " differs from given length " + headerLen + "!");
}
return headerLen;
}
use of org.openhab.binding.insteonplm.internal.utils.Utils.ParsingException in project openhab1-addons by openhab.
the class FeatureTemplateLoader method s_readTemplates.
public static ArrayList<FeatureTemplate> s_readTemplates(InputStream input) throws IOException, ParsingException {
ArrayList<FeatureTemplate> features = new ArrayList<FeatureTemplate>();
try {
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
// Parse it!
Document doc = dBuilder.parse(input);
doc.getDocumentElement().normalize();
Element root = doc.getDocumentElement();
NodeList nodes = root.getChildNodes();
for (int i = 0; i < nodes.getLength(); i++) {
Node node = nodes.item(i);
if (node.getNodeType() == Node.ELEMENT_NODE) {
Element e = (Element) node;
if (e.getTagName().equals("feature")) {
features.add(s_parseFeature(e));
}
}
}
} catch (SAXException e) {
throw new ParsingException("Failed to parse XML!", e);
} catch (ParserConfigurationException e) {
throw new ParsingException("Got parser config exception! ", e);
}
return features;
}
Aggregations