List of usage examples for org.apache.commons.lang StringUtils substringBetween
public static String substringBetween(String str, String open, String close)
Gets the String that is nested in between two Strings.
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 {/*from w w w. j a v a 2s .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 ww . j a v a2 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.WemoHandler.java
/** * The {@link updateWemoState} polls the actual state of a WeMo device and * calls {@link onValueReceived} to update the statemap and channels.. * *///from ww w . j ava 2 s . c om protected void updateWemoState() { String action = "GetBinaryState"; String variable = "BinaryState"; String actionService = "basicevent"; String value = null; if (getThing().getThingTypeUID().getId().equals("insight")) { action = "GetInsightParams"; variable = "InsightParams"; actionService = "insight"; } 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) { logger.trace("State response '{}' for device '{}' received", wemoCallResponse, getThing().getUID()); if (variable.equals("InsightParams")) { value = StringUtils.substringBetween(wemoCallResponse, "<InsightParams>", "</InsightParams>"); } else { value = StringUtils.substringBetween(wemoCallResponse, "<BinaryState>", "</BinaryState>"); } if (value != null) { logger.trace("New state '{}' for device '{}' received", value, getThing().getUID()); this.onValueReceived(variable, value, actionService + "1"); } } } } catch (Exception e) { logger.error("Failed to get actual state for device '{}': {}", getThing().getUID(), e.getMessage()); } }
From source file:org.eclipse.smarthome.binding.wemo.handler.WemoLightHandler.java
/** * The {@link getDeviceState} is used for polling the actual state of a WeMo Light and updating the according * channel states.// w w w . j ava 2s.c o m */ public void getDeviceState() { logger.debug("Request actual state for LightID '{}'", wemoLightID); try { String soapHeader = "\"urn:Belkin:service:bridge:1#GetDeviceStatus\""; 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:GetDeviceStatus xmlns:u=\"urn:Belkin:service:bridge:1\">" + "<DeviceIDs>" + wemoLightID + "</DeviceIDs>" + "</u:GetDeviceStatus>" + "</s:Body>" + "</s:Envelope>"; String wemoURL = getWemoURL(); if (wemoURL != null) { String wemoCallResponse = WemoHttpCall.executeCall(wemoURL, soapHeader, content); if (wemoCallResponse != null) { wemoCallResponse = StringEscapeUtils.unescapeXml(wemoCallResponse); String response = StringUtils.substringBetween(wemoCallResponse, "<CapabilityValue>", "</CapabilityValue>"); logger.trace("wemoNewLightState = {}", response); String[] splitResponse = response.split(","); if (splitResponse[0] != null) { OnOffType binaryState = null; binaryState = splitResponse[0].equals("0") ? OnOffType.OFF : OnOffType.ON; if (binaryState != null) { updateState(CHANNEL_STATE, binaryState); } } if (splitResponse[1] != null) { String splitBrightness[] = splitResponse[1].split(":"); if (splitBrightness[0] != null) { int newBrightnessValue = Integer.valueOf(splitBrightness[0]); int newBrightness = Math.round(newBrightnessValue * 100 / 255); logger.trace("newBrightness = {}", newBrightness); State newBrightnessState = new PercentType(newBrightness); updateState(CHANNEL_BRIGHTNESS, newBrightnessState); currentBrightness = newBrightness; } } } } } catch (Exception e) { throw new RuntimeException("Could not retrieve new Wemo light state", e); } }
From source file:org.eclipse.smarthome.binding.wemo.handler.WemoLightHandler.java
@Override public void onValueReceived(String variable, String value, String service) { logger.trace("Received pair '{}':'{}' (service '{}') for thing '{}'", new Object[] { variable, value, service, this.getThing().getUID() }); String capabilityId = StringUtils.substringBetween(value, "<CapabilityId>", "</CapabilityId>"); String newValue = StringUtils.substringBetween(value, "<Value>", "</Value>"); switch (capabilityId) { case "10006": OnOffType binaryState = null;/*from w w w . j a va2 s .c o m*/ binaryState = newValue.equals("0") ? OnOffType.OFF : OnOffType.ON; if (binaryState != null) { updateState(CHANNEL_STATE, binaryState); } break; case "10008": String splitValue[] = newValue.split(":"); if (splitValue[0] != null) { int newBrightnessValue = Integer.valueOf(splitValue[0]); int newBrightness = Math.round(newBrightnessValue * 100 / 255); State newBrightnessState = new PercentType(newBrightness); updateState(CHANNEL_BRIGHTNESS, newBrightnessState); currentBrightness = newBrightness; } break; } }
From source file:org.eclipse.smarthome.binding.wemo.handler.WemoMakerHandler.java
/** * The {@link updateWemoState} polls the actual state of a WeMo Maker. *//*w w w. j a v a 2s .co 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 = 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 {/* w w w . j a v a2 s. com*/ 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); } }
From source file:org.eclipse.smarthome.binding.yahooweather.handler.YahooWeatherHandler.java
private String getValue(String data, String element, String param) { String tmp = StringUtils.substringAfter(data, element); if (tmp != null) { return StringUtils.substringBetween(tmp, param + "\":\"", "\""); }/*from w w w .j a v a 2 s .co m*/ return null; }
From source file:org.eclipse.smarthome.model.item.internal.GenericItemProvider.java
private Item createItemFromModelItem(ModelItem modelItem) { GenericItem item = null;//from ww w .j ava 2 s. c o m if (modelItem instanceof ModelGroupItem) { ModelGroupItem modelGroupItem = (ModelGroupItem) modelItem; String baseItemType = modelGroupItem.getType(); GenericItem baseItem = createItemOfType(baseItemType, modelGroupItem.getName()); if (baseItem != null) { ModelGroupFunction function = modelGroupItem.getFunction(); if (function == null) { item = new GroupItem(modelGroupItem.getName(), baseItem); } else { item = applyGroupFunction(baseItem, modelGroupItem, function); } } else { item = new GroupItem(modelGroupItem.getName()); } } else { ModelNormalItem normalItem = (ModelNormalItem) modelItem; String itemName = normalItem.getName(); item = createItemOfType(normalItem.getType(), itemName); } if (item != null) { String label = modelItem.getLabel(); String format = StringUtils.substringBetween(label, "[", "]"); if (format != null) { label = StringUtils.substringBefore(label, "[").trim(); stateDescriptions.put(modelItem.getName(), new StateDescription(null, null, null, format, false, null)); } item.setLabel(label); item.setCategory(modelItem.getIcon()); assignTags(modelItem, item); return item; } else { return null; } }
From source file:org.eclipse.wb.internal.core.model.description.helpers.ComponentDescriptionHelper.java
/** * Usually XML parsers don't allow to get content of element with all inner tags, but we want * these tags for description. So, we need special way to get description. Right now it is not * very accurate, but may be will enough for practical purposes. *//*w w w .j a v a2s . c o m*/ private static void setDescriptionWithInnerTags(ComponentDescription componentDescription, ResourceInfo resourceInfo) throws Exception { InputStream stream = resourceInfo.getURL().openStream(); String string = IOUtils2.readString(stream); String description = StringUtils.substringBetween(string, "<description>", "</description>"); if (description != null) { componentDescription.setDescription(description); } }