diff --git a/bundles/org.openhab.ui.basic/src/main/java/org/openhab/ui/basic/internal/render/AbstractWidgetRenderer.java b/bundles/org.openhab.ui.basic/src/main/java/org/openhab/ui/basic/internal/render/AbstractWidgetRenderer.java index 52503ca3e9..4c0b9de94e 100644 --- a/bundles/org.openhab.ui.basic/src/main/java/org/openhab/ui/basic/internal/render/AbstractWidgetRenderer.java +++ b/bundles/org.openhab.ui.basic/src/main/java/org/openhab/ui/basic/internal/render/AbstractWidgetRenderer.java @@ -23,7 +23,6 @@ import org.apache.commons.io.IOUtils; import org.apache.commons.lang.StringEscapeUtils; -import org.apache.commons.lang.StringUtils; import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; import org.openhab.core.i18n.I18nUtil; @@ -95,22 +94,21 @@ public ItemUIRegistry getItemUIRegistry() { */ protected String preprocessSnippet(String originalSnippet, Widget w) { String snippet = originalSnippet; - snippet = StringUtils.replace(snippet, "%widget_id%", itemUIRegistry.getWidgetId(w)); - snippet = StringUtils.replace(snippet, "%icon_type%", ICON_TYPE); - snippet = StringUtils.replace(snippet, "%item%", w.getItem() != null ? w.getItem() : ""); + snippet = snippet.replace("%widget_id%", itemUIRegistry.getWidgetId(w)); + snippet = snippet.replace("%icon_type%", ICON_TYPE); + snippet = snippet.replace("%item%", w.getItem() != null ? w.getItem() : ""); // Optimization: avoid calling 3 times itemUIRegistry.getLabel(w) String text = itemUIRegistry.getLabel(w); - snippet = StringUtils.replace(snippet, "%label%", getLabel(text)); - snippet = StringUtils.replace(snippet, "%value%", getValue(text)); - snippet = StringUtils.replace(snippet, "%has_value%", Boolean.valueOf(hasValue(text)).toString()); - snippet = StringUtils.replace(snippet, "%visibility_class%", - itemUIRegistry.getVisiblity(w) ? "" : "mdl-form__row--hidden"); + snippet = snippet.replace("%label%", getLabel(text)); + snippet = snippet.replace("%value%", getValue(text)); + snippet = snippet.replace("%has_value%", Boolean.valueOf(hasValue(text)).toString()); + snippet = snippet.replace("%visibility_class%", itemUIRegistry.getVisiblity(w) ? "" : "mdl-form__row--hidden"); String state = getState(w); - snippet = StringUtils.replace(snippet, "%state%", escapeURL(state)); + snippet = snippet.replace("%state%", escapeURL(state)); String category = getCategory(w); - snippet = StringUtils.replace(snippet, "%category%", escapeURL(category)); + snippet = snippet.replace("%category%", escapeURL(category)); return snippet; } @@ -263,7 +261,7 @@ protected String processColor(Widget w, String originalSnippet) { if (color != null) { style = "style=\"color:" + color + "\""; } - snippet = StringUtils.replace(snippet, "%labelstyle%", style); + snippet = snippet.replace("%labelstyle%", style); style = ""; color = itemUIRegistry.getValueColor(w); @@ -271,7 +269,7 @@ protected String processColor(Widget w, String originalSnippet) { if (color != null) { style = "style=\"color:" + color + "\""; } - snippet = StringUtils.replace(snippet, "%valuestyle%", style); + snippet = snippet.replace("%valuestyle%", style); return snippet; } diff --git a/bundles/org.openhab.ui.basic/src/main/java/org/openhab/ui/basic/internal/render/ChartRenderer.java b/bundles/org.openhab.ui.basic/src/main/java/org/openhab/ui/basic/internal/render/ChartRenderer.java index 2fd6389565..6fba28247d 100644 --- a/bundles/org.openhab.ui.basic/src/main/java/org/openhab/ui/basic/internal/render/ChartRenderer.java +++ b/bundles/org.openhab.ui.basic/src/main/java/org/openhab/ui/basic/internal/render/ChartRenderer.java @@ -14,7 +14,6 @@ import java.util.Date; -import org.apache.commons.lang.StringUtils; import org.eclipse.emf.common.util.ECollections; import org.eclipse.emf.common.util.EList; import org.eclipse.jdt.annotation.NonNullByDefault; @@ -115,16 +114,16 @@ public EList renderWidget(Widget w, StringBuilder sb, String sitemap) th snippet = preprocessSnippet(snippet, w); if (chart.getRefresh() > 0) { - snippet = StringUtils.replace(snippet, "%update_interval%", Integer.toString(chart.getRefresh())); + snippet = snippet.replace("%update_interval%", Integer.toString(chart.getRefresh())); } else { - snippet = StringUtils.replace(snippet, "%update_interval%", "0"); + snippet = snippet.replace("%update_interval%", "0"); } - snippet = StringUtils.replace(snippet, "%id%", itemUIRegistry.getWidgetId(w)); - snippet = StringUtils.replace(snippet, "%proxied_url%", chartUrl); - snippet = StringUtils.replace(snippet, "%valid_url%", "true"); - snippet = StringUtils.replace(snippet, "%ignore_refresh%", ignoreRefresh ? "true" : "false"); - snippet = StringUtils.replace(snippet, "%url%", url); + snippet = snippet.replace("%id%", itemUIRegistry.getWidgetId(w)); + snippet = snippet.replace("%proxied_url%", chartUrl); + snippet = snippet.replace("%valid_url%", "true"); + snippet = snippet.replace("%ignore_refresh%", ignoreRefresh ? "true" : "false"); + snippet = snippet.replace("%url%", url); sb.append(snippet); } catch (ItemNotFoundException e) { diff --git a/bundles/org.openhab.ui.basic/src/main/java/org/openhab/ui/basic/internal/render/ColorpickerRenderer.java b/bundles/org.openhab.ui.basic/src/main/java/org/openhab/ui/basic/internal/render/ColorpickerRenderer.java index 3831d41bdd..ef84f5b6fc 100644 --- a/bundles/org.openhab.ui.basic/src/main/java/org/openhab/ui/basic/internal/render/ColorpickerRenderer.java +++ b/bundles/org.openhab.ui.basic/src/main/java/org/openhab/ui/basic/internal/render/ColorpickerRenderer.java @@ -12,7 +12,6 @@ */ package org.openhab.ui.basic.internal.render; -import org.apache.commons.lang.StringUtils; import org.eclipse.emf.common.util.ECollections; import org.eclipse.emf.common.util.EList; import org.eclipse.jdt.annotation.NonNullByDefault; @@ -80,27 +79,29 @@ public EList renderWidget(Widget w, StringBuilder sb, String sitemap) th } // Should be called before preprocessSnippet - snippet = StringUtils.replace(snippet, "%state%", hexValue); - snippet = StringUtils.replace(snippet, "%icon_state%", escapeURL(hexValue)); + snippet = snippet.replace("%state%", hexValue); + snippet = snippet.replace("%icon_state%", escapeURL(hexValue)); snippet = preprocessSnippet(snippet, w); - snippet = StringUtils.replace(snippet, "%purelabel%", purelabel); - snippet = StringUtils.replace(snippet, "%frequency%", frequency); - snippet = StringUtils.replace(snippet, "%servletname%", WebAppServlet.SERVLET_NAME); + if (purelabel != null) { + snippet = snippet.replace("%purelabel%", purelabel); + } + snippet = snippet.replace("%frequency%", frequency); + snippet = snippet.replace("%servletname%", WebAppServlet.SERVLET_NAME); String style = ""; String color = itemUIRegistry.getLabelColor(w); if (color != null) { style = "color:" + color; } - snippet = StringUtils.replace(snippet, "%labelstyle%", style); + snippet = snippet.replace("%labelstyle%", style); style = ""; color = itemUIRegistry.getValueColor(w); if (color != null) { style = "color:" + color; } - snippet = StringUtils.replace(snippet, "%valuestyle%", style); + snippet = snippet.replace("%valuestyle%", style); sb.append(snippet); return ECollections.emptyEList(); diff --git a/bundles/org.openhab.ui.basic/src/main/java/org/openhab/ui/basic/internal/render/FrameRenderer.java b/bundles/org.openhab.ui.basic/src/main/java/org/openhab/ui/basic/internal/render/FrameRenderer.java index 2def9f9c72..a8b1af1d4a 100644 --- a/bundles/org.openhab.ui.basic/src/main/java/org/openhab/ui/basic/internal/render/FrameRenderer.java +++ b/bundles/org.openhab.ui.basic/src/main/java/org/openhab/ui/basic/internal/render/FrameRenderer.java @@ -16,7 +16,6 @@ import java.util.List; import org.apache.commons.lang.StringEscapeUtils; -import org.apache.commons.lang.StringUtils; import org.eclipse.emf.common.util.EList; import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.core.i18n.LocaleProvider; @@ -59,8 +58,8 @@ public EList renderWidget(Widget w, StringBuilder sb, String sitemap) th String label = StringEscapeUtils.escapeHtml(itemUIRegistry.getLabel(w)); List frameClassList = new ArrayList<>(); - snippet = StringUtils.replace(snippet, "%label%", label); - snippet = StringUtils.replace(snippet, "%widget_id%", itemUIRegistry.getWidgetId(w)); + snippet = snippet.replace("%label%", label); + snippet = snippet.replace("%widget_id%", itemUIRegistry.getWidgetId(w)); if (label.isEmpty()) { frameClassList.add("mdl-form--no-label"); @@ -70,8 +69,8 @@ public EList renderWidget(Widget w, StringBuilder sb, String sitemap) th frameClassList.add("mdl-form--hidden"); } - String frameClass = StringUtils.join(frameClassList, ' '); - snippet = StringUtils.replace(snippet, "%frame_class%", frameClass); + String frameClass = String.join(" ", frameClassList); + snippet = snippet.replace("%frame_class%", frameClass); // Process the color tags snippet = processColor(w, snippet); diff --git a/bundles/org.openhab.ui.basic/src/main/java/org/openhab/ui/basic/internal/render/GroupRenderer.java b/bundles/org.openhab.ui.basic/src/main/java/org/openhab/ui/basic/internal/render/GroupRenderer.java index 5ef887c487..9fc1df0c56 100644 --- a/bundles/org.openhab.ui.basic/src/main/java/org/openhab/ui/basic/internal/render/GroupRenderer.java +++ b/bundles/org.openhab.ui.basic/src/main/java/org/openhab/ui/basic/internal/render/GroupRenderer.java @@ -12,7 +12,6 @@ */ package org.openhab.ui.basic.internal.render; -import org.apache.commons.lang.StringUtils; import org.eclipse.emf.common.util.ECollections; import org.eclipse.emf.common.util.EList; import org.eclipse.jdt.annotation.NonNullByDefault; @@ -55,7 +54,7 @@ public EList renderWidget(Widget w, StringBuilder sb, String sitemap) th String snippet = getSnippet("group"); snippet = preprocessSnippet(snippet, w); - snippet = StringUtils.replace(snippet, "%id%", itemUIRegistry.getWidgetId(w)); + snippet = snippet.replace("%id%", itemUIRegistry.getWidgetId(w)); // Process the color tags snippet = processColor(w, snippet); diff --git a/bundles/org.openhab.ui.basic/src/main/java/org/openhab/ui/basic/internal/render/ImageRenderer.java b/bundles/org.openhab.ui.basic/src/main/java/org/openhab/ui/basic/internal/render/ImageRenderer.java index cb4745b441..59b79d9ee3 100644 --- a/bundles/org.openhab.ui.basic/src/main/java/org/openhab/ui/basic/internal/render/ImageRenderer.java +++ b/bundles/org.openhab.ui.basic/src/main/java/org/openhab/ui/basic/internal/render/ImageRenderer.java @@ -14,7 +14,6 @@ import java.util.Date; -import org.apache.commons.lang.StringUtils; import org.eclipse.emf.common.util.ECollections; import org.eclipse.emf.common.util.EList; import org.eclipse.jdt.annotation.NonNullByDefault; @@ -63,13 +62,13 @@ public EList renderWidget(Widget w, StringBuilder sb, String sitemap) th String snippet = (image.getChildren().size() > 0) ? getSnippet("image_link") : getSnippet("image"); if (image.getRefresh() > 0) { - snippet = StringUtils.replace(snippet, "%update_interval%", Integer.toString(image.getRefresh())); + snippet = snippet.replace("%update_interval%", Integer.toString(image.getRefresh())); } else { - snippet = StringUtils.replace(snippet, "%update_interval%", "0"); + snippet = snippet.replace("%update_interval%", "0"); } String widgetId = itemUIRegistry.getWidgetId(w); - snippet = StringUtils.replace(snippet, "%id%", widgetId); + snippet = snippet.replace("%id%", widgetId); snippet = preprocessSnippet(snippet, w); boolean validUrl = isValidURL(image.getUrl()); @@ -90,10 +89,10 @@ public EList renderWidget(Widget w, StringBuilder sb, String sitemap) th url = URL_NONE_ICON; ignoreRefresh = true; } - snippet = StringUtils.replace(snippet, "%valid_url%", validUrl ? "true" : "false"); - snippet = StringUtils.replace(snippet, "%proxied_url%", proxiedUrl); - snippet = StringUtils.replace(snippet, "%ignore_refresh%", ignoreRefresh ? "true" : "false"); - snippet = StringUtils.replace(snippet, "%url%", url); + snippet = snippet.replace("%valid_url%", validUrl ? "true" : "false"); + snippet = snippet.replace("%proxied_url%", proxiedUrl); + snippet = snippet.replace("%ignore_refresh%", ignoreRefresh ? "true" : "false"); + snippet = snippet.replace("%url%", url); sb.append(snippet); return ECollections.emptyEList(); diff --git a/bundles/org.openhab.ui.basic/src/main/java/org/openhab/ui/basic/internal/render/ListRenderer.java b/bundles/org.openhab.ui.basic/src/main/java/org/openhab/ui/basic/internal/render/ListRenderer.java index b477cb1107..08d71a120f 100644 --- a/bundles/org.openhab.ui.basic/src/main/java/org/openhab/ui/basic/internal/render/ListRenderer.java +++ b/bundles/org.openhab.ui.basic/src/main/java/org/openhab/ui/basic/internal/render/ListRenderer.java @@ -12,7 +12,6 @@ */ package org.openhab.ui.basic.internal.render; -import org.apache.commons.lang.StringUtils; import org.eclipse.emf.common.util.ECollections; import org.eclipse.emf.common.util.EList; import org.eclipse.jdt.annotation.NonNullByDefault; @@ -63,11 +62,11 @@ public EList renderWidget(Widget w, StringBuilder sb, String sitemap) th if (state != null) { for (String row : state.toString().split(((List) w).getSeparator())) { - rowSB.append(StringUtils.replace(rowSnippet, "%title%", escapeHtml(row))); + rowSB.append(rowSnippet.replace("%title%", escapeHtml(row))); } } - snippet = StringUtils.replace(snippet, "%rows%", rowSB.toString()); + snippet = snippet.replace("%rows%", rowSB.toString()); // Process the color tags snippet = processColor(w, snippet); diff --git a/bundles/org.openhab.ui.basic/src/main/java/org/openhab/ui/basic/internal/render/MapviewRenderer.java b/bundles/org.openhab.ui.basic/src/main/java/org/openhab/ui/basic/internal/render/MapviewRenderer.java index 4a5f118c9f..193b9a6b6a 100644 --- a/bundles/org.openhab.ui.basic/src/main/java/org/openhab/ui/basic/internal/render/MapviewRenderer.java +++ b/bundles/org.openhab.ui.basic/src/main/java/org/openhab/ui/basic/internal/render/MapviewRenderer.java @@ -12,7 +12,6 @@ */ package org.openhab.ui.basic.internal.render; -import org.apache.commons.lang.StringUtils; import org.eclipse.emf.common.util.ECollections; import org.eclipse.emf.common.util.EList; import org.eclipse.jdt.annotation.NonNullByDefault; @@ -67,26 +66,26 @@ public EList renderWidget(Widget w, StringBuilder sb, String sitemap) th PointType pointState = (PointType) state; double latitude = pointState.getLatitude().doubleValue(); double longitude = pointState.getLongitude().doubleValue(); - snippet = StringUtils.replace(snippet, "%url%", MAP_URL); - snippet = StringUtils.replace(snippet, "%lat%", Double.toString(latitude)); - snippet = StringUtils.replace(snippet, "%lon%", Double.toString(longitude)); - snippet = StringUtils.replace(snippet, "%lonminus%", Double.toString(longitude - MAP_ZOOM)); - snippet = StringUtils.replace(snippet, "%lonplus%", Double.toString(longitude + MAP_ZOOM)); - snippet = StringUtils.replace(snippet, "%latminus%", Double.toString(latitude - MAP_ZOOM)); - snippet = StringUtils.replace(snippet, "%latplus%", Double.toString(latitude + MAP_ZOOM)); + snippet = snippet.replace("%url%", MAP_URL); + snippet = snippet.replace("%lat%", Double.toString(latitude)); + snippet = snippet.replace("%lon%", Double.toString(longitude)); + snippet = snippet.replace("%lonminus%", Double.toString(longitude - MAP_ZOOM)); + snippet = snippet.replace("%lonplus%", Double.toString(longitude + MAP_ZOOM)); + snippet = snippet.replace("%latminus%", Double.toString(latitude - MAP_ZOOM)); + snippet = snippet.replace("%latplus%", Double.toString(latitude + MAP_ZOOM)); } else { - snippet = StringUtils.replace(snippet, "%url%", "images/map-marker-off.png"); + snippet = snippet.replace("%url%", "images/map-marker-off.png"); } - snippet = StringUtils.replace(snippet, "%map_url%", MAP_URL); - snippet = StringUtils.replace(snippet, "%map_zoom%", Double.toString(MAP_ZOOM)); + snippet = snippet.replace("%map_url%", MAP_URL); + snippet = snippet.replace("%map_zoom%", Double.toString(MAP_ZOOM)); int height = mapview.getHeight(); if (height == 0) { height = 4; // set default height to something viewable } height = height * 36; - snippet = StringUtils.replace(snippet, "%height%", Integer.toString(height)); + snippet = snippet.replace("%height%", Integer.toString(height)); sb.append(snippet); return ECollections.emptyEList(); diff --git a/bundles/org.openhab.ui.basic/src/main/java/org/openhab/ui/basic/internal/render/PageRenderer.java b/bundles/org.openhab.ui.basic/src/main/java/org/openhab/ui/basic/internal/render/PageRenderer.java index de0c5f08bc..0cf4b2fba2 100644 --- a/bundles/org.openhab.ui.basic/src/main/java/org/openhab/ui/basic/internal/render/PageRenderer.java +++ b/bundles/org.openhab.ui.basic/src/main/java/org/openhab/ui/basic/internal/render/PageRenderer.java @@ -17,7 +17,6 @@ import java.util.List; import java.util.Set; -import org.apache.commons.lang.StringUtils; import org.eclipse.emf.common.util.ECollections; import org.eclipse.emf.common.util.EList; import org.eclipse.emf.ecore.EObject; @@ -109,12 +108,12 @@ public StringBuilder processPage(String id, String sitemap, String label, EList< if (labelPlain.contains("[") && labelPlain.endsWith("]")) { labelPlain = labelPlain.replace("[", "").replace("]", ""); } - snippet = StringUtils.replace(snippet, "%label%", escapeHtml(labelPlain)); - snippet = StringUtils.replace(snippet, "%servletname%", WebAppServlet.SERVLET_NAME); - snippet = StringUtils.replace(snippet, "%sitemap%", sitemap); - snippet = StringUtils.replace(snippet, "%htmlclass%", config.getCssClassList()); - snippet = StringUtils.replace(snippet, "%icon_type%", ICON_TYPE); - snippet = StringUtils.replace(snippet, "%theme%", config.getTheme()); + snippet = snippet.replace("%label%", escapeHtml(labelPlain)); + snippet = snippet.replace("%servletname%", WebAppServlet.SERVLET_NAME); + snippet = snippet.replace("%sitemap%", sitemap); + snippet = snippet.replace("%htmlclass%", config.getCssClassList()); + snippet = snippet.replace("%icon_type%", ICON_TYPE); + snippet = snippet.replace("%theme%", config.getTheme()); String[] parts = snippet.split("%children%"); @@ -139,9 +138,9 @@ private void processChildren(StringBuilder sb_pre, StringBuilder sb_post, EList< if (!(firstChild instanceof Frame || parent instanceof Frame || parent instanceof Sitemap || parent instanceof org.openhab.core.model.sitemap.sitemap.List)) { String frameSnippet = getSnippet("frame"); - frameSnippet = StringUtils.replace(frameSnippet, "%widget_id%", ""); - frameSnippet = StringUtils.replace(frameSnippet, "%label%", ""); - frameSnippet = StringUtils.replace(frameSnippet, "%frame_class%", "mdl-form--no-label"); + frameSnippet = frameSnippet.replace("%widget_id%", ""); + frameSnippet = frameSnippet.replace("%label%", ""); + frameSnippet = frameSnippet.replace("%frame_class%", "mdl-form--no-label"); String[] parts = frameSnippet.split("%children%"); if (parts.length > 1) { @@ -230,26 +229,33 @@ public CharSequence renderSitemapList(Set sitemapProviders) thr StringBuilder sb = new StringBuilder(); if (sitemapList.isEmpty()) { String listEmptySnippet = getSnippet("sitemaps_list_empty"); - listEmptySnippet = StringUtils.replace(listEmptySnippet, "%sitemaps-list-empty.info%", - localizeText("@text/sitemaps-list-empty.info")); + String text = localizeText("@text/sitemaps-list-empty.info"); + if (text != null) { + listEmptySnippet = listEmptySnippet.replace("%sitemaps-list-empty.info%", text); + } sb.append(listEmptySnippet); } else { for (String sitemap : sitemapList) { - sb.append(StringUtils.replace(sitemapSnippet, "%sitemap%", sitemap)); + sb.append(sitemapSnippet.replace("%sitemap%", sitemap)); } } - listSnippet = StringUtils.replace(listSnippet, "%sitemaps-list.welcome%", - localizeText("@text/sitemaps-list.welcome")); - listSnippet = StringUtils.replace(listSnippet, "%sitemaps-list.available-sitemaps%", - localizeText("@text/sitemaps-list.available-sitemaps")); - listSnippet = StringUtils.replace(listSnippet, "%items%", sb.toString()); + String text = localizeText("@text/sitemaps-list.welcome"); + if (text != null) { + listSnippet = listSnippet.replace("%sitemaps-list.welcome%", text); + } + + text = localizeText("@text/sitemaps-list.available-sitemaps"); + if (text != null) { + listSnippet = listSnippet.replace("%sitemaps-list.available-sitemaps%", text); + } + + listSnippet = listSnippet.replace("%items%", sb.toString()); - pageSnippet = StringUtils.replace(pageSnippet, "%title%", "BasicUI"); - pageSnippet = StringUtils.replace(pageSnippet, "%htmlclass%", - config.getCssClassList() + " page-welcome-sitemaps"); - pageSnippet = StringUtils.replace(pageSnippet, "%theme%", config.getTheme()); - pageSnippet = StringUtils.replace(pageSnippet, "%content%", listSnippet); + pageSnippet = pageSnippet.replace("%title%", "BasicUI"); + pageSnippet = pageSnippet.replace("%htmlclass%", config.getCssClassList() + " page-welcome-sitemaps"); + pageSnippet = pageSnippet.replace("%theme%", config.getTheme()); + pageSnippet = pageSnippet.replace("%content%", listSnippet); return pageSnippet; } diff --git a/bundles/org.openhab.ui.basic/src/main/java/org/openhab/ui/basic/internal/render/SelectionRenderer.java b/bundles/org.openhab.ui.basic/src/main/java/org/openhab/ui/basic/internal/render/SelectionRenderer.java index b5cbc80c6d..817657c6f8 100644 --- a/bundles/org.openhab.ui.basic/src/main/java/org/openhab/ui/basic/internal/render/SelectionRenderer.java +++ b/bundles/org.openhab.ui.basic/src/main/java/org/openhab/ui/basic/internal/render/SelectionRenderer.java @@ -12,7 +12,6 @@ */ package org.openhab.ui.basic.internal.render; -import org.apache.commons.lang.StringUtils; import org.eclipse.emf.common.util.ECollections; import org.eclipse.emf.common.util.EList; import org.eclipse.jdt.annotation.NonNullByDefault; @@ -106,10 +105,10 @@ public EList renderWidget(Widget w, StringBuilder sb, String sitemap) th } } } - snippet = StringUtils.replace(snippet, "%rows%", rowSB.toString()); - snippet = StringUtils.replace(snippet, "%value_map%", escapeHtml(jsonObject.toString())); - snippet = StringUtils.replace(snippet, "%label_header%", getLabel(w)); - snippet = StringUtils.replace(snippet, "%value_header%", mappingLabel != null ? mappingLabel : getValue(w)); + snippet = snippet.replace("%rows%", rowSB.toString()); + snippet = snippet.replace("%value_map%", escapeHtml(jsonObject.toString())); + snippet = snippet.replace("%label_header%", getLabel(w)); + snippet = snippet.replace("%value_header%", mappingLabel != null ? mappingLabel : getValue(w)); // Process the color tags snippet = processColor(w, snippet); @@ -128,13 +127,15 @@ public EList renderWidget(Widget w, StringBuilder sb, String sitemap) th if (item instanceof NumberItem && ((NumberItem) item).getDimension() != null) { String unit = getUnitForWidget(w); - command = StringUtils.replace(command, UnitUtils.UNIT_PLACEHOLDER, unit); - label = StringUtils.replace(label, UnitUtils.UNIT_PLACEHOLDER, unit); + if (unit != null) { + command = command.replace(UnitUtils.UNIT_PLACEHOLDER, unit); + label = label.replace(UnitUtils.UNIT_PLACEHOLDER, unit); + } } - rowSnippet = StringUtils.replace(rowSnippet, "%item%", w.getItem() != null ? w.getItem() : ""); - rowSnippet = StringUtils.replace(rowSnippet, "%cmd%", escapeHtml(command)); - rowSnippet = StringUtils.replace(rowSnippet, "%label%", escapeHtml(label)); + rowSnippet = rowSnippet.replace("%item%", w.getItem() != null ? w.getItem() : ""); + rowSnippet = rowSnippet.replace("%cmd%", escapeHtml(command)); + rowSnippet = rowSnippet.replace("%label%", escapeHtml(label)); State compareMappingState = state; if (state instanceof QuantityType) { // convert the item state to the command value for proper @@ -144,9 +145,9 @@ public EList renderWidget(Widget w, StringBuilder sb, String sitemap) th if (compareMappingState != null && compareMappingState.toString().equals(command)) { mappingLabel = label; - rowSnippet = StringUtils.replace(rowSnippet, "%checked%", "checked=\"true\""); + rowSnippet = rowSnippet.replace("%checked%", "checked=\"true\""); } else { - rowSnippet = StringUtils.replace(rowSnippet, "%checked%", ""); + rowSnippet = rowSnippet.replace("%checked%", ""); } rowSB.append(rowSnippet); diff --git a/bundles/org.openhab.ui.basic/src/main/java/org/openhab/ui/basic/internal/render/SetpointRenderer.java b/bundles/org.openhab.ui.basic/src/main/java/org/openhab/ui/basic/internal/render/SetpointRenderer.java index df49ec014d..81f8987d7b 100644 --- a/bundles/org.openhab.ui.basic/src/main/java/org/openhab/ui/basic/internal/render/SetpointRenderer.java +++ b/bundles/org.openhab.ui.basic/src/main/java/org/openhab/ui/basic/internal/render/SetpointRenderer.java @@ -14,7 +14,6 @@ import java.math.BigDecimal; -import org.apache.commons.lang.StringUtils; import org.eclipse.emf.common.util.ECollections; import org.eclipse.emf.common.util.EList; import org.eclipse.jdt.annotation.NonNullByDefault; @@ -75,11 +74,13 @@ public EList renderWidget(Widget w, StringBuilder sb, String sitemap) th String snippet = getSnippet("setpoint"); snippet = preprocessSnippet(snippet, w); - snippet = StringUtils.replace(snippet, "%value%", getValue(w)); - snippet = StringUtils.replace(snippet, "%minValue%", minValue.toString()); - snippet = StringUtils.replace(snippet, "%maxValue%", maxValue.toString()); - snippet = StringUtils.replace(snippet, "%step%", step.toString()); - snippet = StringUtils.replace(snippet, "%unit%", unit); + snippet = snippet.replace("%value%", getValue(w)); + snippet = snippet.replace("%minValue%", minValue.toString()); + snippet = snippet.replace("%maxValue%", maxValue.toString()); + snippet = snippet.replace("%step%", step.toString()); + if (unit != null) { + snippet = snippet.replace("%unit%", unit); + } // Process the color tags snippet = processColor(w, snippet); diff --git a/bundles/org.openhab.ui.basic/src/main/java/org/openhab/ui/basic/internal/render/SliderRenderer.java b/bundles/org.openhab.ui.basic/src/main/java/org/openhab/ui/basic/internal/render/SliderRenderer.java index ae13dd6027..8910858765 100644 --- a/bundles/org.openhab.ui.basic/src/main/java/org/openhab/ui/basic/internal/render/SliderRenderer.java +++ b/bundles/org.openhab.ui.basic/src/main/java/org/openhab/ui/basic/internal/render/SliderRenderer.java @@ -12,7 +12,6 @@ */ package org.openhab.ui.basic.internal.render; -import org.apache.commons.lang.StringUtils; import org.eclipse.emf.common.util.ECollections; import org.eclipse.emf.common.util.EList; import org.eclipse.jdt.annotation.NonNullByDefault; @@ -68,12 +67,14 @@ public EList renderWidget(Widget w, StringBuilder sb, String sitemap) th String unit = getUnitForWidget(w); snippet = preprocessSnippet(snippet, w); - snippet = StringUtils.replace(snippet, "%frequency%", frequency); - snippet = StringUtils.replace(snippet, "%switch%", s.isSwitchEnabled() ? "1" : "0"); - snippet = StringUtils.replace(snippet, "%unit%", unit); - snippet = StringUtils.replace(snippet, "%minValue%", minValueOf(s)); - snippet = StringUtils.replace(snippet, "%maxValue%", maxValueOf(s)); - snippet = StringUtils.replace(snippet, "%step%", stepOf(s)); + snippet = snippet.replace("%frequency%", frequency); + snippet = snippet.replace("%switch%", s.isSwitchEnabled() ? "1" : "0"); + if (unit != null) { + snippet = snippet.replace("%unit%", unit); + } + snippet = snippet.replace("%minValue%", minValueOf(s)); + snippet = snippet.replace("%maxValue%", maxValueOf(s)); + snippet = snippet.replace("%step%", stepOf(s)); // Process the color tags snippet = processColor(w, snippet); diff --git a/bundles/org.openhab.ui.basic/src/main/java/org/openhab/ui/basic/internal/render/SwitchRenderer.java b/bundles/org.openhab.ui.basic/src/main/java/org/openhab/ui/basic/internal/render/SwitchRenderer.java index 39f2b95739..4ff5abc3a5 100644 --- a/bundles/org.openhab.ui.basic/src/main/java/org/openhab/ui/basic/internal/render/SwitchRenderer.java +++ b/bundles/org.openhab.ui.basic/src/main/java/org/openhab/ui/basic/internal/render/SwitchRenderer.java @@ -12,7 +12,6 @@ */ package org.openhab.ui.basic.internal.render; -import org.apache.commons.lang.StringUtils; import org.eclipse.emf.common.util.ECollections; import org.eclipse.emf.common.util.EList; import org.eclipse.jdt.annotation.NonNullByDefault; @@ -136,8 +135,8 @@ public EList renderWidget(Widget w, StringBuilder sb, String sitemap) th buildButton(s, mapping.getLabel(), mapping.getCmd(), -1, nbButtons > 1, item, state, buttons); } } - snippet = StringUtils.replace(snippet, "%buttons%", buttons.toString()); - snippet = StringUtils.replace(snippet, "%count%", Integer.toString(nbButtons)); + snippet = snippet.replace("%buttons%", buttons.toString()); + snippet = snippet.replace("%count%", Integer.toString(nbButtons)); } // Process the color tags @@ -156,17 +155,19 @@ private void buildButton(Switch w, @Nullable String lab, String cmd, int maxLabe if (item instanceof NumberItem && ((NumberItem) item).getDimension() != null) { String unit = getUnitForWidget(w); - command = StringUtils.replace(command, UnitUtils.UNIT_PLACEHOLDER, unit); - label = StringUtils.replace(label, UnitUtils.UNIT_PLACEHOLDER, unit); + if (unit != null) { + command = command.replace(UnitUtils.UNIT_PLACEHOLDER, unit); + label = label.replace(UnitUtils.UNIT_PLACEHOLDER, unit); + } } if (maxLabelSize >= 1 && label.length() > maxLabelSize) { label = label.substring(0, maxLabelSize - 1) + ELLIPSIS; } - button = StringUtils.replace(button, "%item%", w.getItem()); - button = StringUtils.replace(button, "%cmd%", escapeHtml(command)); - button = StringUtils.replace(button, "%label%", escapeHtml(label)); + button = button.replace("%item%", w.getItem()); + button = button.replace("%cmd%", escapeHtml(command)); + button = button.replace("%label%", escapeHtml(label)); String buttonClass; State compareMappingState = state; @@ -180,7 +181,7 @@ private void buildButton(Switch w, @Nullable String lab, String cmd, int maxLabe } else { buttonClass = "mdl-button"; } - button = StringUtils.replace(button, "%class%", buttonClass); + button = button.replace("%class%", buttonClass); buttons.append(button); } diff --git a/bundles/org.openhab.ui.basic/src/main/java/org/openhab/ui/basic/internal/render/TextRenderer.java b/bundles/org.openhab.ui.basic/src/main/java/org/openhab/ui/basic/internal/render/TextRenderer.java index 63415a1aa7..0e14fccbe3 100644 --- a/bundles/org.openhab.ui.basic/src/main/java/org/openhab/ui/basic/internal/render/TextRenderer.java +++ b/bundles/org.openhab.ui.basic/src/main/java/org/openhab/ui/basic/internal/render/TextRenderer.java @@ -12,7 +12,6 @@ */ package org.openhab.ui.basic.internal.render; -import org.apache.commons.lang.StringUtils; import org.eclipse.emf.common.util.ECollections; import org.eclipse.emf.common.util.EList; import org.eclipse.jdt.annotation.NonNullByDefault; @@ -56,7 +55,7 @@ public EList renderWidget(Widget w, StringBuilder sb, String sitemap) th String snippet = (text.getChildren().size() > 0) ? getSnippet("text_link") : getSnippet("text"); snippet = preprocessSnippet(snippet, w); - snippet = StringUtils.replace(snippet, "%id%", itemUIRegistry.getWidgetId(w)); + snippet = snippet.replace("%id%", itemUIRegistry.getWidgetId(w)); // Process the color tags snippet = processColor(w, snippet); diff --git a/bundles/org.openhab.ui.basic/src/main/java/org/openhab/ui/basic/internal/render/VideoRenderer.java b/bundles/org.openhab.ui.basic/src/main/java/org/openhab/ui/basic/internal/render/VideoRenderer.java index 28b14a1f24..3af05490fb 100644 --- a/bundles/org.openhab.ui.basic/src/main/java/org/openhab/ui/basic/internal/render/VideoRenderer.java +++ b/bundles/org.openhab.ui.basic/src/main/java/org/openhab/ui/basic/internal/render/VideoRenderer.java @@ -14,7 +14,6 @@ import java.util.Date; -import org.apache.commons.lang.StringUtils; import org.eclipse.emf.common.util.ECollections; import org.eclipse.emf.common.util.EList; import org.eclipse.jdt.annotation.NonNullByDefault; @@ -81,11 +80,11 @@ public EList renderWidget(Widget w, StringBuilder sb, String sitemap) th } else { url = URL_NONE_ICON; } - snippet = StringUtils.replace(snippet, "%valid_url%", validUrl ? "true" : "false"); - snippet = StringUtils.replace(snippet, "%proxied_url%", proxiedUrl); - snippet = StringUtils.replace(snippet, "%update_interval%", "0"); - snippet = StringUtils.replace(snippet, "%ignore_refresh%", "true"); - snippet = StringUtils.replace(snippet, "%url%", url); + snippet = snippet.replace("%valid_url%", validUrl ? "true" : "false"); + snippet = snippet.replace("%proxied_url%", proxiedUrl); + snippet = snippet.replace("%update_interval%", "0"); + snippet = snippet.replace("%ignore_refresh%", "true"); + snippet = snippet.replace("%url%", url); } else { String mediaType; if (videoWidget.getEncoding() != null && videoWidget.getEncoding().toLowerCase().contains("hls")) { @@ -96,8 +95,8 @@ public EList renderWidget(Widget w, StringBuilder sb, String sitemap) th url = "../proxy?sitemap=" + sitemap + "&widgetId=" + widgetId; mediaType = ""; } - snippet = StringUtils.replace(snippet, "%url%", url); - snippet = StringUtils.replace(snippet, "%media_type%", mediaType); + snippet = snippet.replace("%url%", url); + snippet = snippet.replace("%media_type%", mediaType); } sb.append(snippet); return ECollections.emptyEList(); diff --git a/bundles/org.openhab.ui.basic/src/main/java/org/openhab/ui/basic/internal/render/WebviewRenderer.java b/bundles/org.openhab.ui.basic/src/main/java/org/openhab/ui/basic/internal/render/WebviewRenderer.java index 93f4acc31f..deeb2cd56c 100644 --- a/bundles/org.openhab.ui.basic/src/main/java/org/openhab/ui/basic/internal/render/WebviewRenderer.java +++ b/bundles/org.openhab.ui.basic/src/main/java/org/openhab/ui/basic/internal/render/WebviewRenderer.java @@ -12,7 +12,6 @@ */ package org.openhab.ui.basic.internal.render; -import org.apache.commons.lang.StringUtils; import org.eclipse.emf.common.util.ECollections; import org.eclipse.emf.common.util.EList; import org.eclipse.jdt.annotation.NonNullByDefault; @@ -57,14 +56,14 @@ public EList renderWidget(Widget w, StringBuilder sb, String sitemap) th // Process the color tags snippet = processColor(w, snippet); - snippet = StringUtils.replace(snippet, "%url%", webview.getUrl()); + snippet = snippet.replace("%url%", webview.getUrl()); int height = webview.getHeight(); if (height == 0) { height = 4; // set default height to something viewable } height = height * 36; - snippet = StringUtils.replace(snippet, "%height%", Integer.toString(height)); + snippet = snippet.replace("%height%", Integer.toString(height)); sb.append(snippet); return ECollections.emptyEList(); diff --git a/bundles/org.openhab.ui.basic/src/main/java/org/openhab/ui/basic/internal/servlet/CmdServlet.java b/bundles/org.openhab.ui.basic/src/main/java/org/openhab/ui/basic/internal/servlet/CmdServlet.java index b9fbb07c30..d5293352cb 100644 --- a/bundles/org.openhab.ui.basic/src/main/java/org/openhab/ui/basic/internal/servlet/CmdServlet.java +++ b/bundles/org.openhab.ui.basic/src/main/java/org/openhab/ui/basic/internal/servlet/CmdServlet.java @@ -87,11 +87,12 @@ protected void service(@NonNullByDefault({}) HttpServletRequest req, @NonNullByD // we need a special treatment for the "TOGGLE" command of switches; // this is no command officially supported and must be translated // into real commands by the webapp. - if ((item instanceof SwitchItem || item instanceof GroupItem) && commandName.equals("TOGGLE")) { + if ((item instanceof SwitchItem || item instanceof GroupItem) && "TOGGLE".equals(commandName)) { commandName = OnOffType.ON.equals(item.getStateAs(OnOffType.class)) ? "OFF" : "ON"; } - Command command = TypeParser.parseCommand(item.getAcceptedCommandTypes(), commandName); + Command command = commandName == null ? null + : TypeParser.parseCommand(item.getAcceptedCommandTypes(), commandName); if (command != null) { eventPublisher.post(ItemEventFactory.createCommandEvent(itemName, command)); } else { diff --git a/bundles/org.openhab.ui.cometvisu/src/main/java/org/openhab/ui/cometvisu/internal/StateBeanMessageBodyWriter.java b/bundles/org.openhab.ui.cometvisu/src/main/java/org/openhab/ui/cometvisu/internal/StateBeanMessageBodyWriter.java index cf1fb7d2f8..022be01353 100644 --- a/bundles/org.openhab.ui.cometvisu/src/main/java/org/openhab/ui/cometvisu/internal/StateBeanMessageBodyWriter.java +++ b/bundles/org.openhab.ui.cometvisu/src/main/java/org/openhab/ui/cometvisu/internal/StateBeanMessageBodyWriter.java @@ -27,7 +27,6 @@ import javax.ws.rs.ext.MessageBodyWriter; import javax.ws.rs.ext.Provider; -import org.apache.commons.lang.StringUtils; import org.openhab.ui.cometvisu.internal.backend.model.StateBean; /** @@ -83,7 +82,7 @@ public String serialize(Object bean) { } } if (states.size() > 0) { - msg += StringUtils.join(states, ","); + msg += String.join(",", states); } } msg += "}}";