diff --git a/bundles/org.openhab.binding.amazonechocontrol/pom.xml b/bundles/org.openhab.binding.amazonechocontrol/pom.xml index 336fba1fa4429..ab1d11f0b4abb 100644 --- a/bundles/org.openhab.binding.amazonechocontrol/pom.xml +++ b/bundles/org.openhab.binding.amazonechocontrol/pom.xml @@ -14,4 +14,13 @@ openHAB Add-ons :: Bundles :: Amazon Echo Control Binding + + + org.unbescape + unbescape + 1.1.6.RELEASE + compile + + + diff --git a/bundles/org.openhab.binding.amazonechocontrol/src/main/java/org/openhab/binding/amazonechocontrol/internal/AccountServlet.java b/bundles/org.openhab.binding.amazonechocontrol/src/main/java/org/openhab/binding/amazonechocontrol/internal/AccountServlet.java index 7d75f244545fc..d80f8720892a1 100644 --- a/bundles/org.openhab.binding.amazonechocontrol/src/main/java/org/openhab/binding/amazonechocontrol/internal/AccountServlet.java +++ b/bundles/org.openhab.binding.amazonechocontrol/src/main/java/org/openhab/binding/amazonechocontrol/internal/AccountServlet.java @@ -29,7 +29,6 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import org.apache.commons.lang.StringEscapeUtils; import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; import org.openhab.binding.amazonechocontrol.internal.handler.AccountHandler; @@ -46,6 +45,7 @@ import org.osgi.service.http.NamespaceException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.unbescape.html.HtmlEscape; import com.google.gson.Gson; import com.google.gson.JsonSyntaxException; @@ -365,27 +365,27 @@ private void handleChangeDomain(HttpServletResponse resp, Connection connection) private void handleDefaultPageResult(HttpServletResponse resp, String message, Connection connection) throws IOException { StringBuilder html = createPageStart(""); - html.append(StringEscapeUtils.escapeHtml(message)); + html.append(HtmlEscape.escapeHtml4(message)); // logout link html.append(" "); - html.append(StringEscapeUtils.escapeHtml("Logout")); + html.append(HtmlEscape.escapeHtml4("Logout")); html.append(""); // newdevice link html.append(" | "); - html.append(StringEscapeUtils.escapeHtml("Logout and create new device id")); + html.append(HtmlEscape.escapeHtml4("Logout and create new device id")); html.append(""); // customer id html.append("
Customer Id: "); - html.append(StringEscapeUtils.escapeHtml(connection.getCustomerId())); + html.append(HtmlEscape.escapeHtml4(connection.getCustomerId())); // customer name html.append("
Customer Name: "); - html.append(StringEscapeUtils.escapeHtml(connection.getCustomerName())); + html.append(HtmlEscape.escapeHtml4(connection.getCustomerName())); // device name html.append("
App name: "); - html.append(StringEscapeUtils.escapeHtml(connection.getDeviceName())); + html.append(HtmlEscape.escapeHtml4(connection.getDeviceName())); // connection html.append("
Connected to: "); - html.append(StringEscapeUtils.escapeHtml(connection.getAlexaServer())); + html.append(HtmlEscape.escapeHtml4(connection.getAlexaServer())); // domain html.append(" "); - html.append(StringEscapeUtils.escapeHtml("Check Thing in Main UI")); + html.append(HtmlEscape.escapeHtml4("Check Thing in Main UI")); html.append("

"); // device list @@ -403,28 +403,28 @@ private void handleDefaultPageResult(HttpServletResponse resp, String message, C for (Device device : this.account.getLastKnownDevices()) { html.append(""); - html.append(StringEscapeUtils.escapeHtml(nullReplacement(device.accountName))); + html.append(HtmlEscape.escapeHtml4(nullReplacement(device.accountName))); html.append(""); - html.append(StringEscapeUtils.escapeHtml(nullReplacement(device.serialNumber))); + html.append(HtmlEscape.escapeHtml4(nullReplacement(device.serialNumber))); html.append(""); - html.append(StringEscapeUtils.escapeHtml(device.online ? "Online" : "Offline")); + html.append(HtmlEscape.escapeHtml4(device.online ? "Online" : "Offline")); html.append(""); Thing accountHandler = account.findThingBySerialNumber(device.serialNumber); if (accountHandler != null) { html.append("" - + StringEscapeUtils.escapeHtml(accountHandler.getLabel()) + ""); + + HtmlEscape.escapeHtml4(accountHandler.getLabel()) + ""); } else { html.append("" - + StringEscapeUtils.escapeHtml("Not defined") + ""); + + URLEncoder.encode(device.serialNumber, "UTF8") + "'>" + HtmlEscape.escapeHtml4("Not defined") + + ""); } html.append(""); - html.append(StringEscapeUtils.escapeHtml(nullReplacement(device.deviceFamily))); + html.append(HtmlEscape.escapeHtml4(nullReplacement(device.deviceFamily))); html.append(""); - html.append(StringEscapeUtils.escapeHtml(nullReplacement(device.deviceType))); + html.append(HtmlEscape.escapeHtml4(nullReplacement(device.deviceType))); html.append(""); - html.append(StringEscapeUtils.escapeHtml(nullReplacement(device.deviceOwnerCustomerId))); + html.append(HtmlEscape.escapeHtml4(nullReplacement(device.deviceOwnerCustomerId))); html.append(""); html.append(""); } @@ -434,8 +434,7 @@ private void handleDefaultPageResult(HttpServletResponse resp, String message, C private void handleDevices(HttpServletResponse resp, Connection connection) throws IOException, URISyntaxException, InterruptedException { - returnHtml(connection, resp, - "" + StringEscapeUtils.escapeHtml(connection.getDeviceListJson()) + ""); + returnHtml(connection, resp, "" + HtmlEscape.escapeHtml4(connection.getDeviceListJson()) + ""); } private String nullReplacement(@Nullable String text) { @@ -448,16 +447,16 @@ private String nullReplacement(@Nullable String text) { StringBuilder createPageStart(String title) { StringBuilder html = new StringBuilder(); html.append("" - + StringEscapeUtils.escapeHtml(BINDING_NAME + " - " + this.account.getThing().getLabel())); + + HtmlEscape.escapeHtml4(BINDING_NAME + " - " + this.account.getThing().getLabel())); if (!title.isEmpty()) { html.append(" - "); - html.append(StringEscapeUtils.escapeHtml(title)); + html.append(HtmlEscape.escapeHtml4(title)); } html.append(""); - html.append("

" + StringEscapeUtils.escapeHtml(BINDING_NAME + " - " + this.account.getThing().getLabel())); + html.append("

" + HtmlEscape.escapeHtml4(BINDING_NAME + " - " + this.account.getThing().getLabel())); if (!title.isEmpty()) { html.append(" - "); - html.append(StringEscapeUtils.escapeHtml(title)); + html.append(HtmlEscape.escapeHtml4(title)); } html.append("

"); return html; @@ -466,7 +465,7 @@ StringBuilder createPageStart(String title) { private void createPageEndAndSent(HttpServletResponse resp, StringBuilder html) { // account overview link html.append("
"); - html.append(StringEscapeUtils.escapeHtml("Account overview")); + html.append(HtmlEscape.escapeHtml4("Account overview")); html.append("
"); html.append(""); @@ -497,14 +496,13 @@ private void handleIds(HttpServletResponse resp, Connection connection, Device d private void renderCapabilities(Connection connection, Device device, StringBuilder html) { html.append("

Capabilities

"); html.append(""); - device.getCapabilities().forEach(capability -> html.append("")); + device.getCapabilities().forEach( + capability -> html.append("")); html.append("
Name
") - .append(StringEscapeUtils.escapeHtml(capability)).append("
").append(HtmlEscape.escapeHtml4(capability)).append("
"); } private void renderMusicProviderIdChannel(Connection connection, StringBuilder html) { - html.append("

").append(StringEscapeUtils.escapeHtml("Channel " + CHANNEL_MUSIC_PROVIDER_ID)) - .append("

"); + html.append("

").append(HtmlEscape.escapeHtml4("Channel " + CHANNEL_MUSIC_PROVIDER_ID)).append("

"); html.append(""); List musicProviders = connection.getMusicProviders(); for (JsonMusicProvider musicProvider : musicProviders) { @@ -515,9 +513,9 @@ private void renderMusicProviderIdChannel(Connection connection, StringBuilder h && !providerId.isEmpty() && "AVAILABLE".equals(musicProvider.availability) && displayName != null && !displayName.isEmpty()) { html.append(""); } } @@ -525,7 +523,7 @@ private void renderMusicProviderIdChannel(Connection connection, StringBuilder h } private void renderPlayAlarmSoundChannel(Connection connection, Device device, StringBuilder html) { - html.append("

").append(StringEscapeUtils.escapeHtml("Channel " + CHANNEL_PLAY_ALARM_SOUND)).append("

"); + html.append("

").append(HtmlEscape.escapeHtml4("Channel " + CHANNEL_PLAY_ALARM_SOUND)).append("

"); List notificationSounds = List.of(); String errorMessage = "No notifications sounds found"; try { @@ -542,20 +540,20 @@ private void renderPlayAlarmSoundChannel(Connection connection, Device device, S String providerSoundId = notificationSound.providerId + ":" + notificationSound.id; html.append(""); } } html.append("
NameValue
"); - html.append(StringEscapeUtils.escapeHtml(displayName)); + html.append(HtmlEscape.escapeHtml4(displayName)); html.append(""); - html.append(StringEscapeUtils.escapeHtml(providerId)); + html.append(HtmlEscape.escapeHtml4(providerId)); html.append("
"); - html.append(StringEscapeUtils.escapeHtml(notificationSound.displayName)); + html.append(HtmlEscape.escapeHtml4(notificationSound.displayName)); html.append(""); - html.append(StringEscapeUtils.escapeHtml(providerSoundId)); + html.append(HtmlEscape.escapeHtml4(providerSoundId)); html.append("
"); } else { - html.append(StringEscapeUtils.escapeHtml(errorMessage)); + html.append(HtmlEscape.escapeHtml4(errorMessage)); } } private void renderAmazonMusicPlaylistIdChannel(Connection connection, Device device, StringBuilder html) { - html.append("

").append(StringEscapeUtils.escapeHtml("Channel " + CHANNEL_AMAZON_MUSIC_PLAY_LIST_ID)) + html.append("

").append(HtmlEscape.escapeHtml4("Channel " + CHANNEL_AMAZON_MUSIC_PLAY_LIST_ID)) .append("

"); JsonPlaylists playLists = null; @@ -578,9 +576,9 @@ private void renderAmazonMusicPlaylistIdChannel(Connection connection, Device de PlayList playList = innerLists[0]; if (playList != null && playList.playlistId != null && playList.title != null) { html.append(""); - html.append(StringEscapeUtils.escapeHtml(nullReplacement(playList.title))); + html.append(HtmlEscape.escapeHtml4(nullReplacement(playList.title))); html.append(""); - html.append(StringEscapeUtils.escapeHtml(nullReplacement(playList.playlistId))); + html.append(HtmlEscape.escapeHtml4(nullReplacement(playList.playlistId))); html.append(""); } } @@ -588,13 +586,13 @@ private void renderAmazonMusicPlaylistIdChannel(Connection connection, Device de } html.append(""); } else { - html.append(StringEscapeUtils.escapeHtml(errorMessage)); + html.append(HtmlEscape.escapeHtml4(errorMessage)); } } } private void renderBluetoothMacChannel(Connection connection, Device device, StringBuilder html) { - html.append("

").append(StringEscapeUtils.escapeHtml("Channel " + CHANNEL_BLUETOOTH_MAC)).append("

"); + html.append("

").append(HtmlEscape.escapeHtml4("Channel " + CHANNEL_BLUETOOTH_MAC)).append("

"); JsonBluetoothStates bluetoothStates = connection.getBluetoothConnectionStates(); if (bluetoothStates == null) { return; @@ -615,14 +613,14 @@ private void renderBluetoothMacChannel(Connection connection, Device device, Str html.append(""); for (PairedDevice pairedDevice : pairedDeviceList) { html.append(""); } html.append("
NameValue
"); - html.append(StringEscapeUtils.escapeHtml(nullReplacement(pairedDevice.friendlyName))); + html.append(HtmlEscape.escapeHtml4(nullReplacement(pairedDevice.friendlyName))); html.append(""); - html.append(StringEscapeUtils.escapeHtml(nullReplacement(pairedDevice.address))); + html.append(HtmlEscape.escapeHtml4(nullReplacement(pairedDevice.address))); html.append("
"); } else { - html.append(StringEscapeUtils.escapeHtml("No bluetooth devices paired")); + html.append(HtmlEscape.escapeHtml4("No bluetooth devices paired")); } } } @@ -712,7 +710,7 @@ private void returnHtml(Connection connection, HttpServletResponse resp, String void returnError(HttpServletResponse resp, @Nullable String errorMessage) { try { String message = errorMessage != null ? errorMessage : "null"; - resp.getWriter().write("" + StringEscapeUtils.escapeHtml(message) + "
Try again"); } catch (IOException e) { logger.info("Returning error message failed", e); diff --git a/bundles/org.openhab.binding.amazonechocontrol/src/main/java/org/openhab/binding/amazonechocontrol/internal/BindingServlet.java b/bundles/org.openhab.binding.amazonechocontrol/src/main/java/org/openhab/binding/amazonechocontrol/internal/BindingServlet.java index 951bdba98cc36..b8b2725a3534d 100644 --- a/bundles/org.openhab.binding.amazonechocontrol/src/main/java/org/openhab/binding/amazonechocontrol/internal/BindingServlet.java +++ b/bundles/org.openhab.binding.amazonechocontrol/src/main/java/org/openhab/binding/amazonechocontrol/internal/BindingServlet.java @@ -24,7 +24,6 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import org.apache.commons.lang.StringEscapeUtils; import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; import org.openhab.core.thing.Thing; @@ -32,6 +31,7 @@ import org.osgi.service.http.NamespaceException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.unbescape.html.HtmlEscape; /** * This servlet provides the base navigation page, with hyperlinks for the defined account things @@ -104,8 +104,8 @@ protected void doGet(@Nullable HttpServletRequest req, @Nullable HttpServletResp } StringBuilder html = new StringBuilder(); - html.append("" + StringEscapeUtils.escapeHtml(BINDING_NAME) + ""); - html.append("

" + StringEscapeUtils.escapeHtml(BINDING_NAME) + "

"); + html.append("" + HtmlEscape.escapeHtml4(BINDING_NAME) + ""); + html.append("

" + HtmlEscape.escapeHtml4(BINDING_NAME) + "

"); synchronized (accountHandlers) { if (accountHandlers.isEmpty()) { @@ -113,7 +113,7 @@ protected void doGet(@Nullable HttpServletRequest req, @Nullable HttpServletResp } else { for (Thing accountHandler : accountHandlers) { String url = URLEncoder.encode(accountHandler.getUID().getId(), "UTF8"); - html.append("" + StringEscapeUtils.escapeHtml(accountHandler.getLabel()) + html.append("" + HtmlEscape.escapeHtml4(accountHandler.getLabel()) + "
"); } } diff --git a/bundles/org.openhab.binding.amazonechocontrol/src/main/java/org/openhab/binding/amazonechocontrol/internal/Connection.java b/bundles/org.openhab.binding.amazonechocontrol/src/main/java/org/openhab/binding/amazonechocontrol/internal/Connection.java index b3fb362f373fd..5e2d5a2bfc418 100644 --- a/bundles/org.openhab.binding.amazonechocontrol/src/main/java/org/openhab/binding/amazonechocontrol/internal/Connection.java +++ b/bundles/org.openhab.binding.amazonechocontrol/src/main/java/org/openhab/binding/amazonechocontrol/internal/Connection.java @@ -1194,7 +1194,6 @@ public void smartHomeCommand(String entityId, String action, @Nullable String pr .collect(Collectors.joining(" / "))); } } - } catch (URISyntaxException e) { logger.warn("URL '{}' has invalid format for request '{}': {}", url, requestBody, e.getMessage()); } @@ -1223,7 +1222,6 @@ public List getDeviceNotificationStates() { String json = makeRequestAndReturnString(alexaServer + "/api/device-notification-state"); JsonDeviceNotificationState result = parseJson(json, JsonDeviceNotificationState.class); return Objects.requireNonNullElse(result.deviceNotificationStates, List.of()); - } catch (IOException | URISyntaxException | InterruptedException e) { logger.info("Error getting device notification states", e); } diff --git a/bundles/org.openhab.binding.amazonechocontrol/src/main/java/org/openhab/binding/amazonechocontrol/internal/channelhandler/ChannelHandlerAnnouncement.java b/bundles/org.openhab.binding.amazonechocontrol/src/main/java/org/openhab/binding/amazonechocontrol/internal/channelhandler/ChannelHandlerAnnouncement.java index 4dd7204f921b1..5ef1bd941b903 100644 --- a/bundles/org.openhab.binding.amazonechocontrol/src/main/java/org/openhab/binding/amazonechocontrol/internal/channelhandler/ChannelHandlerAnnouncement.java +++ b/bundles/org.openhab.binding.amazonechocontrol/src/main/java/org/openhab/binding/amazonechocontrol/internal/channelhandler/ChannelHandlerAnnouncement.java @@ -16,13 +16,13 @@ import java.net.URISyntaxException; import java.util.Objects; -import org.apache.commons.lang.StringEscapeUtils; import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; import org.openhab.binding.amazonechocontrol.internal.Connection; import org.openhab.binding.amazonechocontrol.internal.jsons.JsonDevices.Device; import org.openhab.core.library.types.StringType; import org.openhab.core.types.Command; +import org.unbescape.xml.XmlEscape; import com.google.gson.Gson; import com.google.gson.JsonSyntaxException; @@ -72,7 +72,7 @@ public boolean tryHandleCommand(Device device, Connection connection, String cha Boolean sound = request.sound; if (sound != null) { if (!sound && !speak.startsWith("")) { - speak = "" + StringEscapeUtils.escapeXml(speak) + ""; + speak = "" + XmlEscape.escapeXml10(speak) + ""; } if (sound && speak.startsWith("")) { body = "Error: The combination of sound and speak in SSML syntax is not allowed"; @@ -87,8 +87,7 @@ public boolean tryHandleCommand(Device device, Connection connection, String cha } catch (JsonSyntaxException e) { body = "Invalid Json." + e.getLocalizedMessage(); title = "Error"; - speak = "" + StringEscapeUtils.escapeXml(body) - + ""; + speak = "" + XmlEscape.escapeXml10(body) + ""; body = e.getLocalizedMessage(); } }