remove dependency on o.a.c.l (#9835)
Signed-off-by: Jan N. Klug <jan.n.klug@rub.de>
This commit is contained in:
parent
675de38272
commit
2afb06948a
|
@ -14,4 +14,13 @@
|
||||||
|
|
||||||
<name>openHAB Add-ons :: Bundles :: Amazon Echo Control Binding</name>
|
<name>openHAB Add-ons :: Bundles :: Amazon Echo Control Binding</name>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.unbescape</groupId>
|
||||||
|
<artifactId>unbescape</artifactId>
|
||||||
|
<version>1.1.6.RELEASE</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
|
|
@ -29,7 +29,6 @@ import javax.servlet.http.HttpServlet;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
import org.apache.commons.lang.StringEscapeUtils;
|
|
||||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||||
import org.eclipse.jdt.annotation.Nullable;
|
import org.eclipse.jdt.annotation.Nullable;
|
||||||
import org.openhab.binding.amazonechocontrol.internal.handler.AccountHandler;
|
import org.openhab.binding.amazonechocontrol.internal.handler.AccountHandler;
|
||||||
|
@ -46,6 +45,7 @@ import org.osgi.service.http.HttpService;
|
||||||
import org.osgi.service.http.NamespaceException;
|
import org.osgi.service.http.NamespaceException;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.unbescape.html.HtmlEscape;
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.google.gson.JsonSyntaxException;
|
import com.google.gson.JsonSyntaxException;
|
||||||
|
@ -365,27 +365,27 @@ public class AccountServlet extends HttpServlet {
|
||||||
private void handleDefaultPageResult(HttpServletResponse resp, String message, Connection connection)
|
private void handleDefaultPageResult(HttpServletResponse resp, String message, Connection connection)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
StringBuilder html = createPageStart("");
|
StringBuilder html = createPageStart("");
|
||||||
html.append(StringEscapeUtils.escapeHtml(message));
|
html.append(HtmlEscape.escapeHtml4(message));
|
||||||
// logout link
|
// logout link
|
||||||
html.append(" <a href='" + servletUrl + "/logout' >");
|
html.append(" <a href='" + servletUrl + "/logout' >");
|
||||||
html.append(StringEscapeUtils.escapeHtml("Logout"));
|
html.append(HtmlEscape.escapeHtml4("Logout"));
|
||||||
html.append("</a>");
|
html.append("</a>");
|
||||||
// newdevice link
|
// newdevice link
|
||||||
html.append(" | <a href='" + servletUrl + "/newdevice' >");
|
html.append(" | <a href='" + servletUrl + "/newdevice' >");
|
||||||
html.append(StringEscapeUtils.escapeHtml("Logout and create new device id"));
|
html.append(HtmlEscape.escapeHtml4("Logout and create new device id"));
|
||||||
html.append("</a>");
|
html.append("</a>");
|
||||||
// customer id
|
// customer id
|
||||||
html.append("<br>Customer Id: ");
|
html.append("<br>Customer Id: ");
|
||||||
html.append(StringEscapeUtils.escapeHtml(connection.getCustomerId()));
|
html.append(HtmlEscape.escapeHtml4(connection.getCustomerId()));
|
||||||
// customer name
|
// customer name
|
||||||
html.append("<br>Customer Name: ");
|
html.append("<br>Customer Name: ");
|
||||||
html.append(StringEscapeUtils.escapeHtml(connection.getCustomerName()));
|
html.append(HtmlEscape.escapeHtml4(connection.getCustomerName()));
|
||||||
// device name
|
// device name
|
||||||
html.append("<br>App name: ");
|
html.append("<br>App name: ");
|
||||||
html.append(StringEscapeUtils.escapeHtml(connection.getDeviceName()));
|
html.append(HtmlEscape.escapeHtml4(connection.getDeviceName()));
|
||||||
// connection
|
// connection
|
||||||
html.append("<br>Connected to: ");
|
html.append("<br>Connected to: ");
|
||||||
html.append(StringEscapeUtils.escapeHtml(connection.getAlexaServer()));
|
html.append(HtmlEscape.escapeHtml4(connection.getAlexaServer()));
|
||||||
// domain
|
// domain
|
||||||
html.append(" <a href='");
|
html.append(" <a href='");
|
||||||
html.append(servletUrl);
|
html.append(servletUrl);
|
||||||
|
@ -394,7 +394,7 @@ public class AccountServlet extends HttpServlet {
|
||||||
// Main UI link
|
// Main UI link
|
||||||
html.append("<br><a href='/#!/settings/things/" + BINDING_ID + ":"
|
html.append("<br><a href='/#!/settings/things/" + BINDING_ID + ":"
|
||||||
+ URLEncoder.encode(THING_TYPE_ACCOUNT.getId(), "UTF8") + ":" + URLEncoder.encode(id, "UTF8") + "'>");
|
+ URLEncoder.encode(THING_TYPE_ACCOUNT.getId(), "UTF8") + ":" + URLEncoder.encode(id, "UTF8") + "'>");
|
||||||
html.append(StringEscapeUtils.escapeHtml("Check Thing in Main UI"));
|
html.append(HtmlEscape.escapeHtml4("Check Thing in Main UI"));
|
||||||
html.append("</a><br><br>");
|
html.append("</a><br><br>");
|
||||||
|
|
||||||
// device list
|
// device list
|
||||||
|
@ -403,28 +403,28 @@ public class AccountServlet extends HttpServlet {
|
||||||
for (Device device : this.account.getLastKnownDevices()) {
|
for (Device device : this.account.getLastKnownDevices()) {
|
||||||
|
|
||||||
html.append("<tr><td>");
|
html.append("<tr><td>");
|
||||||
html.append(StringEscapeUtils.escapeHtml(nullReplacement(device.accountName)));
|
html.append(HtmlEscape.escapeHtml4(nullReplacement(device.accountName)));
|
||||||
html.append("</td><td>");
|
html.append("</td><td>");
|
||||||
html.append(StringEscapeUtils.escapeHtml(nullReplacement(device.serialNumber)));
|
html.append(HtmlEscape.escapeHtml4(nullReplacement(device.serialNumber)));
|
||||||
html.append("</td><td>");
|
html.append("</td><td>");
|
||||||
html.append(StringEscapeUtils.escapeHtml(device.online ? "Online" : "Offline"));
|
html.append(HtmlEscape.escapeHtml4(device.online ? "Online" : "Offline"));
|
||||||
html.append("</td><td>");
|
html.append("</td><td>");
|
||||||
Thing accountHandler = account.findThingBySerialNumber(device.serialNumber);
|
Thing accountHandler = account.findThingBySerialNumber(device.serialNumber);
|
||||||
if (accountHandler != null) {
|
if (accountHandler != null) {
|
||||||
html.append("<a href='" + servletUrl + "/ids/?serialNumber="
|
html.append("<a href='" + servletUrl + "/ids/?serialNumber="
|
||||||
+ URLEncoder.encode(device.serialNumber, "UTF8") + "'>"
|
+ URLEncoder.encode(device.serialNumber, "UTF8") + "'>"
|
||||||
+ StringEscapeUtils.escapeHtml(accountHandler.getLabel()) + "</a>");
|
+ HtmlEscape.escapeHtml4(accountHandler.getLabel()) + "</a>");
|
||||||
} else {
|
} else {
|
||||||
html.append("<a href='" + servletUrl + "/ids/?serialNumber="
|
html.append("<a href='" + servletUrl + "/ids/?serialNumber="
|
||||||
+ URLEncoder.encode(device.serialNumber, "UTF8") + "'>"
|
+ URLEncoder.encode(device.serialNumber, "UTF8") + "'>" + HtmlEscape.escapeHtml4("Not defined")
|
||||||
+ StringEscapeUtils.escapeHtml("Not defined") + "</a>");
|
+ "</a>");
|
||||||
}
|
}
|
||||||
html.append("</td><td>");
|
html.append("</td><td>");
|
||||||
html.append(StringEscapeUtils.escapeHtml(nullReplacement(device.deviceFamily)));
|
html.append(HtmlEscape.escapeHtml4(nullReplacement(device.deviceFamily)));
|
||||||
html.append("</td><td>");
|
html.append("</td><td>");
|
||||||
html.append(StringEscapeUtils.escapeHtml(nullReplacement(device.deviceType)));
|
html.append(HtmlEscape.escapeHtml4(nullReplacement(device.deviceType)));
|
||||||
html.append("</td><td>");
|
html.append("</td><td>");
|
||||||
html.append(StringEscapeUtils.escapeHtml(nullReplacement(device.deviceOwnerCustomerId)));
|
html.append(HtmlEscape.escapeHtml4(nullReplacement(device.deviceOwnerCustomerId)));
|
||||||
html.append("</td>");
|
html.append("</td>");
|
||||||
html.append("</tr>");
|
html.append("</tr>");
|
||||||
}
|
}
|
||||||
|
@ -434,8 +434,7 @@ public class AccountServlet extends HttpServlet {
|
||||||
|
|
||||||
private void handleDevices(HttpServletResponse resp, Connection connection)
|
private void handleDevices(HttpServletResponse resp, Connection connection)
|
||||||
throws IOException, URISyntaxException, InterruptedException {
|
throws IOException, URISyntaxException, InterruptedException {
|
||||||
returnHtml(connection, resp,
|
returnHtml(connection, resp, "<html>" + HtmlEscape.escapeHtml4(connection.getDeviceListJson()) + "</html>");
|
||||||
"<html>" + StringEscapeUtils.escapeHtml(connection.getDeviceListJson()) + "</html>");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private String nullReplacement(@Nullable String text) {
|
private String nullReplacement(@Nullable String text) {
|
||||||
|
@ -448,16 +447,16 @@ public class AccountServlet extends HttpServlet {
|
||||||
StringBuilder createPageStart(String title) {
|
StringBuilder createPageStart(String title) {
|
||||||
StringBuilder html = new StringBuilder();
|
StringBuilder html = new StringBuilder();
|
||||||
html.append("<html><head><title>"
|
html.append("<html><head><title>"
|
||||||
+ StringEscapeUtils.escapeHtml(BINDING_NAME + " - " + this.account.getThing().getLabel()));
|
+ HtmlEscape.escapeHtml4(BINDING_NAME + " - " + this.account.getThing().getLabel()));
|
||||||
if (!title.isEmpty()) {
|
if (!title.isEmpty()) {
|
||||||
html.append(" - ");
|
html.append(" - ");
|
||||||
html.append(StringEscapeUtils.escapeHtml(title));
|
html.append(HtmlEscape.escapeHtml4(title));
|
||||||
}
|
}
|
||||||
html.append("</title><head><body>");
|
html.append("</title><head><body>");
|
||||||
html.append("<h1>" + StringEscapeUtils.escapeHtml(BINDING_NAME + " - " + this.account.getThing().getLabel()));
|
html.append("<h1>" + HtmlEscape.escapeHtml4(BINDING_NAME + " - " + this.account.getThing().getLabel()));
|
||||||
if (!title.isEmpty()) {
|
if (!title.isEmpty()) {
|
||||||
html.append(" - ");
|
html.append(" - ");
|
||||||
html.append(StringEscapeUtils.escapeHtml(title));
|
html.append(HtmlEscape.escapeHtml4(title));
|
||||||
}
|
}
|
||||||
html.append("</h1>");
|
html.append("</h1>");
|
||||||
return html;
|
return html;
|
||||||
|
@ -466,7 +465,7 @@ public class AccountServlet extends HttpServlet {
|
||||||
private void createPageEndAndSent(HttpServletResponse resp, StringBuilder html) {
|
private void createPageEndAndSent(HttpServletResponse resp, StringBuilder html) {
|
||||||
// account overview link
|
// account overview link
|
||||||
html.append("<br><a href='" + servletUrl + "/../' >");
|
html.append("<br><a href='" + servletUrl + "/../' >");
|
||||||
html.append(StringEscapeUtils.escapeHtml("Account overview"));
|
html.append(HtmlEscape.escapeHtml4("Account overview"));
|
||||||
html.append("</a><br>");
|
html.append("</a><br>");
|
||||||
|
|
||||||
html.append("</body></html>");
|
html.append("</body></html>");
|
||||||
|
@ -497,14 +496,13 @@ public class AccountServlet extends HttpServlet {
|
||||||
private void renderCapabilities(Connection connection, Device device, StringBuilder html) {
|
private void renderCapabilities(Connection connection, Device device, StringBuilder html) {
|
||||||
html.append("<h2>Capabilities</h2>");
|
html.append("<h2>Capabilities</h2>");
|
||||||
html.append("<table><tr><th align='left'>Name</th></tr>");
|
html.append("<table><tr><th align='left'>Name</th></tr>");
|
||||||
device.getCapabilities().forEach(capability -> html.append("<tr><td>")
|
device.getCapabilities().forEach(
|
||||||
.append(StringEscapeUtils.escapeHtml(capability)).append("</td></tr>"));
|
capability -> html.append("<tr><td>").append(HtmlEscape.escapeHtml4(capability)).append("</td></tr>"));
|
||||||
html.append("</table>");
|
html.append("</table>");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void renderMusicProviderIdChannel(Connection connection, StringBuilder html) {
|
private void renderMusicProviderIdChannel(Connection connection, StringBuilder html) {
|
||||||
html.append("<h2>").append(StringEscapeUtils.escapeHtml("Channel " + CHANNEL_MUSIC_PROVIDER_ID))
|
html.append("<h2>").append(HtmlEscape.escapeHtml4("Channel " + CHANNEL_MUSIC_PROVIDER_ID)).append("</h2>");
|
||||||
.append("</h2>");
|
|
||||||
html.append("<table><tr><th align='left'>Name</th><th align='left'>Value</th></tr>");
|
html.append("<table><tr><th align='left'>Name</th><th align='left'>Value</th></tr>");
|
||||||
List<JsonMusicProvider> musicProviders = connection.getMusicProviders();
|
List<JsonMusicProvider> musicProviders = connection.getMusicProviders();
|
||||||
for (JsonMusicProvider musicProvider : musicProviders) {
|
for (JsonMusicProvider musicProvider : musicProviders) {
|
||||||
|
@ -515,9 +513,9 @@ public class AccountServlet extends HttpServlet {
|
||||||
&& !providerId.isEmpty() && "AVAILABLE".equals(musicProvider.availability) && displayName != null
|
&& !providerId.isEmpty() && "AVAILABLE".equals(musicProvider.availability) && displayName != null
|
||||||
&& !displayName.isEmpty()) {
|
&& !displayName.isEmpty()) {
|
||||||
html.append("<tr><td>");
|
html.append("<tr><td>");
|
||||||
html.append(StringEscapeUtils.escapeHtml(displayName));
|
html.append(HtmlEscape.escapeHtml4(displayName));
|
||||||
html.append("</td><td>");
|
html.append("</td><td>");
|
||||||
html.append(StringEscapeUtils.escapeHtml(providerId));
|
html.append(HtmlEscape.escapeHtml4(providerId));
|
||||||
html.append("</td></tr>");
|
html.append("</td></tr>");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -525,7 +523,7 @@ public class AccountServlet extends HttpServlet {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void renderPlayAlarmSoundChannel(Connection connection, Device device, StringBuilder html) {
|
private void renderPlayAlarmSoundChannel(Connection connection, Device device, StringBuilder html) {
|
||||||
html.append("<h2>").append(StringEscapeUtils.escapeHtml("Channel " + CHANNEL_PLAY_ALARM_SOUND)).append("</h2>");
|
html.append("<h2>").append(HtmlEscape.escapeHtml4("Channel " + CHANNEL_PLAY_ALARM_SOUND)).append("</h2>");
|
||||||
List<JsonNotificationSound> notificationSounds = List.of();
|
List<JsonNotificationSound> notificationSounds = List.of();
|
||||||
String errorMessage = "No notifications sounds found";
|
String errorMessage = "No notifications sounds found";
|
||||||
try {
|
try {
|
||||||
|
@ -542,20 +540,20 @@ public class AccountServlet extends HttpServlet {
|
||||||
String providerSoundId = notificationSound.providerId + ":" + notificationSound.id;
|
String providerSoundId = notificationSound.providerId + ":" + notificationSound.id;
|
||||||
|
|
||||||
html.append("<tr><td>");
|
html.append("<tr><td>");
|
||||||
html.append(StringEscapeUtils.escapeHtml(notificationSound.displayName));
|
html.append(HtmlEscape.escapeHtml4(notificationSound.displayName));
|
||||||
html.append("</td><td>");
|
html.append("</td><td>");
|
||||||
html.append(StringEscapeUtils.escapeHtml(providerSoundId));
|
html.append(HtmlEscape.escapeHtml4(providerSoundId));
|
||||||
html.append("</td></tr>");
|
html.append("</td></tr>");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
html.append("</table>");
|
html.append("</table>");
|
||||||
} else {
|
} else {
|
||||||
html.append(StringEscapeUtils.escapeHtml(errorMessage));
|
html.append(HtmlEscape.escapeHtml4(errorMessage));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void renderAmazonMusicPlaylistIdChannel(Connection connection, Device device, StringBuilder html) {
|
private void renderAmazonMusicPlaylistIdChannel(Connection connection, Device device, StringBuilder html) {
|
||||||
html.append("<h2>").append(StringEscapeUtils.escapeHtml("Channel " + CHANNEL_AMAZON_MUSIC_PLAY_LIST_ID))
|
html.append("<h2>").append(HtmlEscape.escapeHtml4("Channel " + CHANNEL_AMAZON_MUSIC_PLAY_LIST_ID))
|
||||||
.append("</h2>");
|
.append("</h2>");
|
||||||
|
|
||||||
JsonPlaylists playLists = null;
|
JsonPlaylists playLists = null;
|
||||||
|
@ -578,9 +576,9 @@ public class AccountServlet extends HttpServlet {
|
||||||
PlayList playList = innerLists[0];
|
PlayList playList = innerLists[0];
|
||||||
if (playList != null && playList.playlistId != null && playList.title != null) {
|
if (playList != null && playList.playlistId != null && playList.title != null) {
|
||||||
html.append("<tr><td>");
|
html.append("<tr><td>");
|
||||||
html.append(StringEscapeUtils.escapeHtml(nullReplacement(playList.title)));
|
html.append(HtmlEscape.escapeHtml4(nullReplacement(playList.title)));
|
||||||
html.append("</td><td>");
|
html.append("</td><td>");
|
||||||
html.append(StringEscapeUtils.escapeHtml(nullReplacement(playList.playlistId)));
|
html.append(HtmlEscape.escapeHtml4(nullReplacement(playList.playlistId)));
|
||||||
html.append("</td></tr>");
|
html.append("</td></tr>");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -588,13 +586,13 @@ public class AccountServlet extends HttpServlet {
|
||||||
}
|
}
|
||||||
html.append("</table>");
|
html.append("</table>");
|
||||||
} else {
|
} else {
|
||||||
html.append(StringEscapeUtils.escapeHtml(errorMessage));
|
html.append(HtmlEscape.escapeHtml4(errorMessage));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void renderBluetoothMacChannel(Connection connection, Device device, StringBuilder html) {
|
private void renderBluetoothMacChannel(Connection connection, Device device, StringBuilder html) {
|
||||||
html.append("<h2>").append(StringEscapeUtils.escapeHtml("Channel " + CHANNEL_BLUETOOTH_MAC)).append("</h2>");
|
html.append("<h2>").append(HtmlEscape.escapeHtml4("Channel " + CHANNEL_BLUETOOTH_MAC)).append("</h2>");
|
||||||
JsonBluetoothStates bluetoothStates = connection.getBluetoothConnectionStates();
|
JsonBluetoothStates bluetoothStates = connection.getBluetoothConnectionStates();
|
||||||
if (bluetoothStates == null) {
|
if (bluetoothStates == null) {
|
||||||
return;
|
return;
|
||||||
|
@ -615,14 +613,14 @@ public class AccountServlet extends HttpServlet {
|
||||||
html.append("<table><tr><th align='left'>Name</th><th align='left'>Value</th></tr>");
|
html.append("<table><tr><th align='left'>Name</th><th align='left'>Value</th></tr>");
|
||||||
for (PairedDevice pairedDevice : pairedDeviceList) {
|
for (PairedDevice pairedDevice : pairedDeviceList) {
|
||||||
html.append("<tr><td>");
|
html.append("<tr><td>");
|
||||||
html.append(StringEscapeUtils.escapeHtml(nullReplacement(pairedDevice.friendlyName)));
|
html.append(HtmlEscape.escapeHtml4(nullReplacement(pairedDevice.friendlyName)));
|
||||||
html.append("</td><td>");
|
html.append("</td><td>");
|
||||||
html.append(StringEscapeUtils.escapeHtml(nullReplacement(pairedDevice.address)));
|
html.append(HtmlEscape.escapeHtml4(nullReplacement(pairedDevice.address)));
|
||||||
html.append("</td></tr>");
|
html.append("</td></tr>");
|
||||||
}
|
}
|
||||||
html.append("</table>");
|
html.append("</table>");
|
||||||
} else {
|
} else {
|
||||||
html.append(StringEscapeUtils.escapeHtml("No bluetooth devices paired"));
|
html.append(HtmlEscape.escapeHtml4("No bluetooth devices paired"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -712,7 +710,7 @@ public class AccountServlet extends HttpServlet {
|
||||||
void returnError(HttpServletResponse resp, @Nullable String errorMessage) {
|
void returnError(HttpServletResponse resp, @Nullable String errorMessage) {
|
||||||
try {
|
try {
|
||||||
String message = errorMessage != null ? errorMessage : "null";
|
String message = errorMessage != null ? errorMessage : "null";
|
||||||
resp.getWriter().write("<html>" + StringEscapeUtils.escapeHtml(message) + "<br><a href='" + servletUrl
|
resp.getWriter().write("<html>" + HtmlEscape.escapeHtml4(message) + "<br><a href='" + servletUrl
|
||||||
+ "'>Try again</a></html>");
|
+ "'>Try again</a></html>");
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
logger.info("Returning error message failed", e);
|
logger.info("Returning error message failed", e);
|
||||||
|
|
|
@ -24,7 +24,6 @@ import javax.servlet.http.HttpServlet;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
import org.apache.commons.lang.StringEscapeUtils;
|
|
||||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||||
import org.eclipse.jdt.annotation.Nullable;
|
import org.eclipse.jdt.annotation.Nullable;
|
||||||
import org.openhab.core.thing.Thing;
|
import org.openhab.core.thing.Thing;
|
||||||
|
@ -32,6 +31,7 @@ import org.osgi.service.http.HttpService;
|
||||||
import org.osgi.service.http.NamespaceException;
|
import org.osgi.service.http.NamespaceException;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.unbescape.html.HtmlEscape;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This servlet provides the base navigation page, with hyperlinks for the defined account things
|
* This servlet provides the base navigation page, with hyperlinks for the defined account things
|
||||||
|
@ -104,8 +104,8 @@ public class BindingServlet extends HttpServlet {
|
||||||
}
|
}
|
||||||
|
|
||||||
StringBuilder html = new StringBuilder();
|
StringBuilder html = new StringBuilder();
|
||||||
html.append("<html><head><title>" + StringEscapeUtils.escapeHtml(BINDING_NAME) + "</title><head><body>");
|
html.append("<html><head><title>" + HtmlEscape.escapeHtml4(BINDING_NAME) + "</title><head><body>");
|
||||||
html.append("<h1>" + StringEscapeUtils.escapeHtml(BINDING_NAME) + "</h1>");
|
html.append("<h1>" + HtmlEscape.escapeHtml4(BINDING_NAME) + "</h1>");
|
||||||
|
|
||||||
synchronized (accountHandlers) {
|
synchronized (accountHandlers) {
|
||||||
if (accountHandlers.isEmpty()) {
|
if (accountHandlers.isEmpty()) {
|
||||||
|
@ -113,7 +113,7 @@ public class BindingServlet extends HttpServlet {
|
||||||
} else {
|
} else {
|
||||||
for (Thing accountHandler : accountHandlers) {
|
for (Thing accountHandler : accountHandlers) {
|
||||||
String url = URLEncoder.encode(accountHandler.getUID().getId(), "UTF8");
|
String url = URLEncoder.encode(accountHandler.getUID().getId(), "UTF8");
|
||||||
html.append("<a href='./" + url + " '>" + StringEscapeUtils.escapeHtml(accountHandler.getLabel())
|
html.append("<a href='./" + url + " '>" + HtmlEscape.escapeHtml4(accountHandler.getLabel())
|
||||||
+ "</a><br>");
|
+ "</a><br>");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1194,7 +1194,6 @@ public class Connection {
|
||||||
.collect(Collectors.joining(" / ")));
|
.collect(Collectors.joining(" / ")));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (URISyntaxException e) {
|
} catch (URISyntaxException e) {
|
||||||
logger.warn("URL '{}' has invalid format for request '{}': {}", url, requestBody, e.getMessage());
|
logger.warn("URL '{}' has invalid format for request '{}': {}", url, requestBody, e.getMessage());
|
||||||
}
|
}
|
||||||
|
@ -1223,7 +1222,6 @@ public class Connection {
|
||||||
String json = makeRequestAndReturnString(alexaServer + "/api/device-notification-state");
|
String json = makeRequestAndReturnString(alexaServer + "/api/device-notification-state");
|
||||||
JsonDeviceNotificationState result = parseJson(json, JsonDeviceNotificationState.class);
|
JsonDeviceNotificationState result = parseJson(json, JsonDeviceNotificationState.class);
|
||||||
return Objects.requireNonNullElse(result.deviceNotificationStates, List.of());
|
return Objects.requireNonNullElse(result.deviceNotificationStates, List.of());
|
||||||
|
|
||||||
} catch (IOException | URISyntaxException | InterruptedException e) {
|
} catch (IOException | URISyntaxException | InterruptedException e) {
|
||||||
logger.info("Error getting device notification states", e);
|
logger.info("Error getting device notification states", e);
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,13 +16,13 @@ import java.io.IOException;
|
||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
import org.apache.commons.lang.StringEscapeUtils;
|
|
||||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||||
import org.eclipse.jdt.annotation.Nullable;
|
import org.eclipse.jdt.annotation.Nullable;
|
||||||
import org.openhab.binding.amazonechocontrol.internal.Connection;
|
import org.openhab.binding.amazonechocontrol.internal.Connection;
|
||||||
import org.openhab.binding.amazonechocontrol.internal.jsons.JsonDevices.Device;
|
import org.openhab.binding.amazonechocontrol.internal.jsons.JsonDevices.Device;
|
||||||
import org.openhab.core.library.types.StringType;
|
import org.openhab.core.library.types.StringType;
|
||||||
import org.openhab.core.types.Command;
|
import org.openhab.core.types.Command;
|
||||||
|
import org.unbescape.xml.XmlEscape;
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.google.gson.JsonSyntaxException;
|
import com.google.gson.JsonSyntaxException;
|
||||||
|
@ -72,7 +72,7 @@ public class ChannelHandlerAnnouncement extends ChannelHandler {
|
||||||
Boolean sound = request.sound;
|
Boolean sound = request.sound;
|
||||||
if (sound != null) {
|
if (sound != null) {
|
||||||
if (!sound && !speak.startsWith("<speak>")) {
|
if (!sound && !speak.startsWith("<speak>")) {
|
||||||
speak = "<speak>" + StringEscapeUtils.escapeXml(speak) + "</speak>";
|
speak = "<speak>" + XmlEscape.escapeXml10(speak) + "</speak>";
|
||||||
}
|
}
|
||||||
if (sound && speak.startsWith("<speak>")) {
|
if (sound && speak.startsWith("<speak>")) {
|
||||||
body = "Error: The combination of sound and speak in SSML syntax is not allowed";
|
body = "Error: The combination of sound and speak in SSML syntax is not allowed";
|
||||||
|
@ -87,8 +87,7 @@ public class ChannelHandlerAnnouncement extends ChannelHandler {
|
||||||
} catch (JsonSyntaxException e) {
|
} catch (JsonSyntaxException e) {
|
||||||
body = "Invalid Json." + e.getLocalizedMessage();
|
body = "Invalid Json." + e.getLocalizedMessage();
|
||||||
title = "Error";
|
title = "Error";
|
||||||
speak = "<speak><lang xml:lang=\"en-US\">" + StringEscapeUtils.escapeXml(body)
|
speak = "<speak><lang xml:lang=\"en-US\">" + XmlEscape.escapeXml10(body) + "</lang></speak>";
|
||||||
+ "</lang></speak>";
|
|
||||||
body = e.getLocalizedMessage();
|
body = e.getLocalizedMessage();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue