List of usage examples for org.xml.sax InputSource setCharacterStream
public void setCharacterStream(Reader characterStream)
From source file:org.auscope.portal.server.web.controllers.GridLoginController.java
/** * Parses the request data and sets attributes accordingly. * * @param requestData the data to parse//w w w . j av a 2 s . c om */ private RequestData parseRequestData(final String requestData) { InputSource is = new InputSource(); is.setCharacterStream(new StringReader(URLDecoder.decode(requestData).trim())); RequestData rd = new RequestData(); try { DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); Document doc = builder.parse(is); rd.authToken = doc.getElementsByTagName("AuthorizationToken").item(0).getFirstChild().getNodeValue(); rd.certDN = doc.getElementsByTagName("Subject").item(0).getFirstChild().getNodeValue(); // parse and add extensions rd.certExtensions = new ArrayList<CertificateExtension>(); NodeList certExt = doc.getElementsByTagName("CertificateExtension"); for (int i = 0; i < certExt.getLength(); i++) { String name = ((Element) certExt.item(i)).getAttribute("name"); String value = certExt.item(i).getFirstChild().getNodeValue(); CertificateExtension ext = CertificateExtensionFactory.createCertificateExtension(name, value); rd.certExtensions.add(ext); } } catch (Exception e) { logger.error(e.getMessage()); } return rd; }
From source file:org.auscope.portal.server.web.controllers.GridLoginController.java
/** * Processes the SLCS response and tries to generate a grid proxy from * the extracted certificate and key./*from ww w .jav a2 s . com*/ */ private void processSlcsResponse(HttpServletRequest request) throws GeneralSecurityException, Exception { String slcsResponse = extractSlcsResponse(request); logger.debug("SLCSResponse:\n" + slcsResponse); RequestData rd = parseRequestData(slcsResponse); String certCN = rd.certDN.split("CN=")[1]; String shibCN = (String) request.getSession().getAttribute("Shib-Person-commonName") + " " + (String) request.getSession().getAttribute("Shib-Shared-Token"); logger.info("SessionID: |" + request.getSession().getId() + "|; shibCN: |" + shibCN + "|"); if (!certCN.equals(shibCN)) { logger.error(certCN + " != " + shibCN); throw new GeneralSecurityException("Certificate is not for current user!"); } CertificateKeys certKeys = new CertificateKeys(2048, new char[0]); CertificateRequest req = new CertificateRequest(certKeys, rd.certDN, rd.certExtensions); logger.info("Requesting signed certificate..."); URL certRespURL = new URL(SLCS_URL + "certificate?AuthorizationToken=" + rd.authToken + "&CertificateSigningRequest=" + URLEncoder.encode(req.getPEMEncoded(), "UTF-8")); BufferedReader certRespReader = new BufferedReader(new InputStreamReader(certRespURL.openStream())); StringBuffer certResp = new StringBuffer(); String inputLine; while ((inputLine = certRespReader.readLine()) != null) { certResp.append(inputLine); certResp.append('\n'); } certRespReader.close(); InputSource is = new InputSource(); is.setCharacterStream(new StringReader(certResp.toString().trim())); DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); Document doc = builder.parse(is); String status = doc.getElementsByTagName("Status").item(0).getFirstChild().getNodeValue(); logger.info("Response status: " + status); if (!status.equals("Error")) { String certStr = doc.getElementsByTagName("Certificate").item(0).getFirstChild().getNodeValue(); InputStream in = new ByteArrayInputStream(certStr.getBytes()); X509Certificate certificate = CertUtil.loadCertificate(in); Object credential = gridAccess.initProxy(certKeys.getPrivate(), certificate, PROXY_LIFETIME); if (credential == null) { throw new Exception("Proxy generation failed"); } else { logger.info("Storing credentials in session."); request.getSession().setAttribute("userCred", credential); } } logger.debug("certDN: " + rd.certDN); request.getSession().setAttribute("certDN", rd.certDN); }
From source file:org.castor.xmlctf.xmldiff.xml.XMLFileReader.java
/** * Reads an XML Document into an BaseNode from the provided file. * * @return the BaseNode/* w w w. j ava 2s . c o m*/ * @throws java.io.IOException if any exception occurs during parsing */ public XMLNode read() throws java.io.IOException { XMLNode node = null; try { InputSource source = new InputSource(); source.setSystemId(_location); source.setCharacterStream(new FileReader(_file)); XMLContentHandler builder = new XMLContentHandler(); _parser.setContentHandler(builder); _parser.parse(source); node = builder.getRoot(); } catch (SAXException sx) { Exception nested = sx.getException(); SAXParseException sxp = null; if (sx instanceof SAXParseException) { sxp = (SAXParseException) sx; } else if (nested != null && (nested instanceof SAXParseException)) { sxp = (SAXParseException) nested; } else { throw new NestedIOException(sx); } String err = new StringBuilder(sxp.toString()).append("\n - ").append(sxp.getSystemId()) .append("; line: ").append(sxp.getLineNumber()).append(", column: ") .append(sxp.getColumnNumber()).toString(); throw new NestedIOException(err, sx); } Root root = (Root) node; return root; }
From source file:org.dhatim.delivery.AbstractParser.java
protected InputSource createInputSource(Source source, String contentEncoding) { // Also attach the underlying stream to the InputSource... if (source instanceof StreamSource) { StreamSource streamSource = (StreamSource) source; InputStream inputStream;//w w w. j av a2s.c om Reader reader; inputStream = getInputStream(streamSource); reader = streamSource.getReader(); if (reader == null) { if (inputStream == null) { throw new SmooksException( "Invalid StreamSource. Unable to extract an InputStream (even by systemId) or Reader instance."); } reader = streamToReader(inputStream, contentEncoding); } InputSource inputSource = new InputSource(); inputSource.setByteStream(inputStream); inputSource.setCharacterStream(reader); return inputSource; } else { return new InputSource(getReader(source, contentEncoding)); } }
From source file:org.easyrec.plugin.profileduke.duke.datasource.utils.EasyrecXMLFormatParser.java
/** * Takes an XML string with the profile and creates statements out * of the properties for the StatementHandler * * @param xmlString string with the profile XML * @param tenantId tenantId of the actual tenant * @param itemId itemId of the item with the profile * @param itemType itemType of the item with the profile *//*from ww w . j a va2 s .com*/ private void xmlParser(String xmlString, int tenantId, int itemId, int itemType) { String idString = Integer.toString(tenantId) + Integer.toString(itemId) + Integer.toString(itemType); try { DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); InputSource is = new InputSource(); is.setCharacterStream(new StringReader(xmlString)); String subject = idString; handler.statement(subject, "ID", idString, true); handler.statement(subject, "ItemID", Integer.toString(itemId), true); Document doc = dBuilder.parse(is); doc.getDocumentElement().normalize(); ProfileDukeGenerator.logger .debug("File: " + idString + " Root element: " + doc.getDocumentElement().getNodeName()); NodeList nList = doc.getElementsByTagName("profile"); // create a map of props to check later if the properties from the profile are // also in the duke configuration HashMap<String, Property> propertyList = new HashMap<String, Property>(props.size()); for (Property property : props) propertyList.put(property.getName(), property); for (int i = 0; i < nList.getLength(); i++) { Node node = nList.item(i); if (node.getNodeType() == Node.ELEMENT_NODE) { Element element = (Element) node; NodeList propertyNodes = element.getElementsByTagName("*"); for (int j = 0; j < propertyNodes.getLength(); j++) { String propertyName = propertyNodes.item(j).getNodeName(); NodeList childNodes = propertyNodes.item(j).getChildNodes(); String propertyValue; if (childNodes.getLength() > 0) { propertyValue = childNodes.item(0).getNodeValue(); } else { continue; } if (propertyList.containsKey(propertyName)) { if (propertyList.get(propertyName).isConcatenateMultiValues()) propertyValue = StringUtils.replace(propertyValue, " ", "~"); handler.statement(subject, propertyName, propertyValue, true); } } } } } catch (Exception e) { logger.warn("An error occurred!", e); } }
From source file:org.easyrec.taglib.ProfileRenderer.java
/** * This function generates a XML document of the given XML String * * @param profileXML//from ww w. java 2s.c om * @return The XmlDocument of the given XML string */ private Document generateXmlDocument(String profileXML) throws SAXException { try { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); InputSource is = new InputSource(); is.setCharacterStream(new StringReader(profileXML)); return db.parse(is); } catch (ParserConfigurationException e) { logger.warn("An error occurred!", e); } catch (IOException e) { logger.warn("An error occurred!", e); e.printStackTrace(); } return null; }
From source file:org.eclipse.smarthome.binding.wemo.discovery.WemoLinkDiscoveryService.java
@Override protected void startScan() { logger.trace("Starting WeMoEndDevice discovery on WeMo Link {}", wemoBridgeHandler.getThing().getUID()); try {//w w w .ja v a 2 s . c o m String devUDN = "uuid:" + wemoBridgeHandler.getThing().getConfiguration().get(UDN).toString(); logger.trace("devUDN = '{}'", devUDN); String soapHeader = "\"urn:Belkin:service:bridge:1#GetEndDevices\""; String content = "<?xml version=\"1.0\"?>" + "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">" + "<s:Body>" + "<u:GetEndDevices xmlns:u=\"urn:Belkin:service:bridge:1\">" + "<DevUDN>" + devUDN + "</DevUDN><ReqListType>PAIRED_LIST</ReqListType>" + "</u:GetEndDevices>" + "</s:Body>" + "</s:Envelope>"; URL descriptorURL = service.getDescriptorURL(this); if (descriptorURL != null) { String deviceURL = StringUtils.substringBefore(descriptorURL.toString(), "/setup.xml"); String wemoURL = deviceURL + "/upnp/control/bridge1"; String endDeviceRequest = WemoHttpCall.executeCall(wemoURL, soapHeader, content); if (endDeviceRequest != null) { logger.trace("endDeviceRequest answered '{}'", endDeviceRequest); try { String stringParser = StringUtils.substringBetween(endDeviceRequest, "<DeviceLists>", "</DeviceLists>"); stringParser = StringEscapeUtils.unescapeXml(stringParser); // check if there are already paired devices with WeMo Link if ("0".equals(stringParser)) { logger.debug("There are no devices connected with WeMo Link. Exit discovery"); return; } // Build parser for received <DeviceList> DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); InputSource is = new InputSource(); is.setCharacterStream(new StringReader(stringParser)); Document doc = db.parse(is); NodeList nodes = doc.getElementsByTagName("DeviceInfo"); // iterate the devices for (int i = 0; i < nodes.getLength(); i++) { Element element = (Element) nodes.item(i); NodeList deviceIndex = element.getElementsByTagName("DeviceIndex"); Element line = (Element) deviceIndex.item(0); logger.trace("DeviceIndex: " + getCharacterDataFromElement(line)); NodeList deviceID = element.getElementsByTagName("DeviceID"); line = (Element) deviceID.item(0); String endDeviceID = getCharacterDataFromElement(line); logger.trace("DeviceID: " + endDeviceID); NodeList friendlyName = element.getElementsByTagName("FriendlyName"); line = (Element) friendlyName.item(0); String endDeviceName = getCharacterDataFromElement(line); logger.trace("FriendlyName: " + endDeviceName); NodeList vendor = element.getElementsByTagName("Manufacturer"); line = (Element) vendor.item(0); String endDeviceVendor = getCharacterDataFromElement(line); logger.trace("Manufacturer: " + endDeviceVendor); NodeList model = element.getElementsByTagName("ModelCode"); line = (Element) model.item(0); String endDeviceModelID = getCharacterDataFromElement(line); endDeviceModelID = endDeviceModelID.replaceAll(NORMALIZE_ID_REGEX, "_"); logger.trace("ModelCode: " + endDeviceModelID); if (SUPPORTED_THING_TYPES.contains(new ThingTypeUID(BINDING_ID, endDeviceModelID))) { logger.debug("Discovered a WeMo LED Light thing with ID '{}'", endDeviceID); ThingUID bridgeUID = wemoBridgeHandler.getThing().getUID(); ThingTypeUID thingTypeUID = new ThingTypeUID(BINDING_ID, endDeviceModelID); if (thingTypeUID.equals(THING_TYPE_MZ100)) { String thingLightId = endDeviceID; ThingUID thingUID = new ThingUID(thingTypeUID, bridgeUID, thingLightId); Map<String, Object> properties = new HashMap<>(1); properties.put(DEVICE_ID, endDeviceID); DiscoveryResult discoveryResult = DiscoveryResultBuilder.create(thingUID) .withProperties(properties) .withBridge(wemoBridgeHandler.getThing().getUID()) .withLabel(endDeviceName).build(); thingDiscovered(discoveryResult); } } else { logger.debug("Discovered an unsupported device :"); logger.debug("DeviceIndex : " + getCharacterDataFromElement(line)); logger.debug("DeviceID : " + endDeviceID); logger.debug("FriendlyName: " + endDeviceName); logger.debug("Manufacturer: " + endDeviceVendor); logger.debug("ModelCode : " + endDeviceModelID); } } } catch (Exception e) { logger.error("Failed to parse endDevices for bridge '{}'", wemoBridgeHandler.getThing().getUID(), e); } } } } catch (Exception e) { logger.error("Failed to get endDevices for bridge '{}'", wemoBridgeHandler.getThing().getUID(), e); } }
From source file:org.eclipse.smarthome.binding.wemo.handler.WemoCoffeeHandler.java
/** * The {@link updateWemoState} polls the actual state of a WeMo CoffeeMaker. *///from w w w . j a va2 s . c o m protected void updateWemoState() { String action = "GetAttributes"; String actionService = "deviceevent"; String soapHeader = "\"urn:Belkin:service:" + actionService + ":1#" + action + "\""; String content = "<?xml version=\"1.0\"?>" + "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">" + "<s:Body>" + "<u:" + action + " xmlns:u=\"urn:Belkin:service:" + actionService + ":1\">" + "</u:" + action + ">" + "</s:Body>" + "</s:Envelope>"; try { String wemoURL = getWemoURL(actionService); if (wemoURL != null) { String wemoCallResponse = wemoHttpCaller.executeCall(wemoURL, soapHeader, content); if (wemoCallResponse != null) { try { String stringParser = StringUtils.substringBetween(wemoCallResponse, "<attributeList>", "</attributeList>"); // Due to Belkins bad response formatting, we need to run this twice. stringParser = StringEscapeUtils.unescapeXml(stringParser); stringParser = StringEscapeUtils.unescapeXml(stringParser); logger.trace("CoffeeMaker response '{}' for device '{}' received", stringParser, getThing().getUID()); stringParser = "<data>" + stringParser + "</data>"; DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); InputSource is = new InputSource(); is.setCharacterStream(new StringReader(stringParser)); Document doc = db.parse(is); NodeList nodes = doc.getElementsByTagName("attribute"); // iterate the attributes for (int i = 0; i < nodes.getLength(); i++) { Element element = (Element) nodes.item(i); NodeList deviceIndex = element.getElementsByTagName("name"); Element line = (Element) deviceIndex.item(0); String attributeName = getCharacterDataFromElement(line); logger.trace("attributeName: {}", attributeName); NodeList deviceID = element.getElementsByTagName("value"); line = (Element) deviceID.item(0); String attributeValue = getCharacterDataFromElement(line); logger.trace("attributeValue: {}", attributeValue); switch (attributeName) { case "Mode": State newMode = new StringType("Brewing"); switch (attributeValue) { case "0": updateState(CHANNEL_STATE, OnOffType.ON); newMode = new StringType("Refill"); updateState(CHANNEL_COFFEEMODE, newMode); break; case "1": updateState(CHANNEL_STATE, OnOffType.OFF); newMode = new StringType("PlaceCarafe"); updateState(CHANNEL_COFFEEMODE, newMode); break; case "2": updateState(CHANNEL_STATE, OnOffType.OFF); newMode = new StringType("RefillWater"); updateState(CHANNEL_COFFEEMODE, newMode); break; case "3": updateState(CHANNEL_STATE, OnOffType.OFF); newMode = new StringType("Ready"); updateState(CHANNEL_COFFEEMODE, newMode); break; case "4": updateState(CHANNEL_STATE, OnOffType.ON); newMode = new StringType("Brewing"); updateState(CHANNEL_COFFEEMODE, newMode); break; case "5": updateState(CHANNEL_STATE, OnOffType.OFF); newMode = new StringType("Brewed"); updateState(CHANNEL_COFFEEMODE, newMode); break; case "6": updateState(CHANNEL_STATE, OnOffType.OFF); newMode = new StringType("CleaningBrewing"); updateState(CHANNEL_COFFEEMODE, newMode); break; case "7": updateState(CHANNEL_STATE, OnOffType.OFF); newMode = new StringType("CleaningSoaking"); updateState(CHANNEL_COFFEEMODE, newMode); break; case "8": updateState(CHANNEL_STATE, OnOffType.OFF); newMode = new StringType("BrewFailCarafeRemoved"); updateState(CHANNEL_COFFEEMODE, newMode); break; } break; case "ModeTime": if (attributeValue != null) { State newAttributeValue = new DecimalType(attributeValue); updateState(CHANNEL_MODETIME, newAttributeValue); } break; case "TimeRemaining": if (attributeValue != null) { State newAttributeValue = new DecimalType(attributeValue); updateState(CHANNEL_TIMEREMAINING, newAttributeValue); } break; case "WaterLevelReached": if (attributeValue != null) { State newAttributeValue = new DecimalType(attributeValue); updateState(CHANNEL_WATERLEVELREACHED, newAttributeValue); } break; case "CleanAdvise": if (attributeValue != null) { State newAttributeValue = attributeValue.equals("0") ? OnOffType.OFF : OnOffType.ON; updateState(CHANNEL_CLEANADVISE, newAttributeValue); } break; case "FilterAdvise": if (attributeValue != null) { State newAttributeValue = attributeValue.equals("0") ? OnOffType.OFF : OnOffType.ON; updateState(CHANNEL_FILTERADVISE, newAttributeValue); } break; case "Brewed": if (attributeValue != null) { State newAttributeValue = getDateTimeState(attributeValue); if (newAttributeValue != null) { updateState(CHANNEL_BREWED, newAttributeValue); } } break; case "LastCleaned": if (attributeValue != null) { State newAttributeValue = getDateTimeState(attributeValue); if (newAttributeValue != null) { updateState(CHANNEL_LASTCLEANED, newAttributeValue); } } break; } } } catch (Exception e) { logger.error("Failed to parse attributeList for WeMo CoffeMaker '{}'", this.getThing().getUID(), e); } } } } catch (Exception e) { logger.error("Failed to get attributes for device '{}'", getThing().getUID(), e); } }
From source file:org.eclipse.smarthome.binding.wemo.handler.WemoMakerHandler.java
/** * The {@link updateWemoState} polls the actual state of a WeMo Maker. *///from www . j av a 2 s . c om protected void updateWemoState() { String action = "GetAttributes"; String actionService = "deviceevent"; String soapHeader = "\"urn:Belkin:service:" + actionService + ":1#" + action + "\""; String content = "<?xml version=\"1.0\"?>" + "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">" + "<s:Body>" + "<u:" + action + " xmlns:u=\"urn:Belkin:service:" + actionService + ":1\">" + "</u:" + action + ">" + "</s:Body>" + "</s:Envelope>"; try { String wemoURL = getWemoURL(actionService); if (wemoURL != null) { String wemoCallResponse = WemoHttpCall.executeCall(wemoURL, soapHeader, content); if (wemoCallResponse != null) { try { String stringParser = StringUtils.substringBetween(wemoCallResponse, "<attributeList>", "</attributeList>"); // Due to Belkins bad response formatting, we need to run this twice. stringParser = StringEscapeUtils.unescapeXml(stringParser); stringParser = StringEscapeUtils.unescapeXml(stringParser); logger.trace("Maker response '{}' for device '{}' received", stringParser, getThing().getUID()); stringParser = "<data>" + stringParser + "</data>"; DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); InputSource is = new InputSource(); is.setCharacterStream(new StringReader(stringParser)); Document doc = db.parse(is); NodeList nodes = doc.getElementsByTagName("attribute"); // iterate the attributes for (int i = 0; i < nodes.getLength(); i++) { Element element = (Element) nodes.item(i); NodeList deviceIndex = element.getElementsByTagName("name"); Element line = (Element) deviceIndex.item(0); String attributeName = getCharacterDataFromElement(line); logger.trace("attributeName: " + attributeName); NodeList deviceID = element.getElementsByTagName("value"); line = (Element) deviceID.item(0); String attributeValue = getCharacterDataFromElement(line); logger.trace("attributeValue: " + attributeValue); switch (attributeName) { case "Switch": State relayState = attributeValue.equals("0") ? OnOffType.OFF : OnOffType.ON; if (relayState != null) { logger.debug("New relayState '{}' for device '{}' received", relayState, getThing().getUID()); updateState(CHANNEL_RELAY, relayState); } break; case "Sensor": State sensorState = attributeValue.equals("1") ? OnOffType.OFF : OnOffType.ON; if (sensorState != null) { logger.debug("New sensorState '{}' for device '{}' received", sensorState, getThing().getUID()); updateState(CHANNEL_SENSOR, sensorState); } break; } } } catch (Exception e) { logger.error("Failed to parse attributeList for WeMo Maker '{}'", this.getThing().getUID(), e); } } } } catch (Exception e) { logger.error("Failed to get attributes for device '{}'", getThing().getUID(), e); } }
From source file:org.eclipse.smarthome.binding.wemo.internal.discovery.WemoLinkDiscoveryService.java
@Override public void startScan() { logger.trace("Starting WeMoEndDevice discovery on WeMo Link {}", wemoBridgeHandler.getThing().getUID()); try {//from ww w .ja v a2 s . c o m String devUDN = "uuid:" + wemoBridgeHandler.getThing().getConfiguration().get(UDN).toString(); logger.trace("devUDN = '{}'", devUDN); String soapHeader = "\"urn:Belkin:service:bridge:1#GetEndDevices\""; String content = "<?xml version=\"1.0\"?>" + "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">" + "<s:Body>" + "<u:GetEndDevices xmlns:u=\"urn:Belkin:service:bridge:1\">" + "<DevUDN>" + devUDN + "</DevUDN><ReqListType>PAIRED_LIST</ReqListType>" + "</u:GetEndDevices>" + "</s:Body>" + "</s:Envelope>"; URL descriptorURL = service.getDescriptorURL(this); if (descriptorURL != null) { String deviceURL = StringUtils.substringBefore(descriptorURL.toString(), "/setup.xml"); String wemoURL = deviceURL + "/upnp/control/bridge1"; String endDeviceRequest = wemoHttpCaller.executeCall(wemoURL, soapHeader, content); if (endDeviceRequest != null) { logger.trace("endDeviceRequest answered '{}'", endDeviceRequest); try { String stringParser = StringUtils.substringBetween(endDeviceRequest, "<DeviceLists>", "</DeviceLists>"); stringParser = StringEscapeUtils.unescapeXml(stringParser); // check if there are already paired devices with WeMo Link if ("0".equals(stringParser)) { logger.debug("There are no devices connected with WeMo Link. Exit discovery"); return; } // Build parser for received <DeviceList> DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); InputSource is = new InputSource(); is.setCharacterStream(new StringReader(stringParser)); Document doc = db.parse(is); NodeList nodes = doc.getElementsByTagName("DeviceInfo"); // iterate the devices for (int i = 0; i < nodes.getLength(); i++) { Element element = (Element) nodes.item(i); NodeList deviceIndex = element.getElementsByTagName("DeviceIndex"); Element line = (Element) deviceIndex.item(0); logger.trace("DeviceIndex: {}", getCharacterDataFromElement(line)); NodeList deviceID = element.getElementsByTagName("DeviceID"); line = (Element) deviceID.item(0); String endDeviceID = getCharacterDataFromElement(line); logger.trace("DeviceID: {}", endDeviceID); NodeList friendlyName = element.getElementsByTagName("FriendlyName"); line = (Element) friendlyName.item(0); String endDeviceName = getCharacterDataFromElement(line); logger.trace("FriendlyName: {}", endDeviceName); NodeList vendor = element.getElementsByTagName("Manufacturer"); line = (Element) vendor.item(0); String endDeviceVendor = getCharacterDataFromElement(line); logger.trace("Manufacturer: {}", endDeviceVendor); NodeList model = element.getElementsByTagName("ModelCode"); line = (Element) model.item(0); String endDeviceModelID = getCharacterDataFromElement(line); endDeviceModelID = endDeviceModelID.replaceAll(NORMALIZE_ID_REGEX, "_"); logger.trace("ModelCode: {}", endDeviceModelID); if (SUPPORTED_THING_TYPES.contains(new ThingTypeUID(BINDING_ID, endDeviceModelID))) { logger.debug("Discovered a WeMo LED Light thing with ID '{}'", endDeviceID); ThingUID bridgeUID = wemoBridgeHandler.getThing().getUID(); ThingTypeUID thingTypeUID = new ThingTypeUID(BINDING_ID, endDeviceModelID); if (thingTypeUID.equals(THING_TYPE_MZ100)) { String thingLightId = endDeviceID; ThingUID thingUID = new ThingUID(thingTypeUID, bridgeUID, thingLightId); Map<String, Object> properties = new HashMap<>(1); properties.put(DEVICE_ID, endDeviceID); DiscoveryResult discoveryResult = DiscoveryResultBuilder.create(thingUID) .withProperties(properties) .withBridge(wemoBridgeHandler.getThing().getUID()) .withLabel(endDeviceName).build(); thingDiscovered(discoveryResult); } } else { logger.debug("Discovered an unsupported device :"); logger.debug("DeviceIndex : {}", getCharacterDataFromElement(line)); logger.debug("DeviceID : {}", endDeviceID); logger.debug("FriendlyName: {}", endDeviceName); logger.debug("Manufacturer: {}", endDeviceVendor); logger.debug("ModelCode : {}", endDeviceModelID); } } } catch (Exception e) { logger.error("Failed to parse endDevices for bridge '{}'", wemoBridgeHandler.getThing().getUID(), e); } } } } catch (Exception e) { logger.error("Failed to get endDevices for bridge '{}'", wemoBridgeHandler.getThing().getUID(), e); } }