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;
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;
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(" <a href='" + servletUrl + "/logout' >");
- html.append(StringEscapeUtils.escapeHtml("Logout"));
+ html.append(HtmlEscape.escapeHtml4("Logout"));
html.append("</a>");
// newdevice link
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>");
// customer id
html.append("<br>Customer Id: ");
- html.append(StringEscapeUtils.escapeHtml(connection.getCustomerId()));
+ html.append(HtmlEscape.escapeHtml4(connection.getCustomerId()));
// customer name
html.append("<br>Customer Name: ");
- html.append(StringEscapeUtils.escapeHtml(connection.getCustomerName()));
+ html.append(HtmlEscape.escapeHtml4(connection.getCustomerName()));
// device name
html.append("<br>App name: ");
- html.append(StringEscapeUtils.escapeHtml(connection.getDeviceName()));
+ html.append(HtmlEscape.escapeHtml4(connection.getDeviceName()));
// connection
html.append("<br>Connected to: ");
- html.append(StringEscapeUtils.escapeHtml(connection.getAlexaServer()));
+ html.append(HtmlEscape.escapeHtml4(connection.getAlexaServer()));
// domain
html.append(" <a href='");
html.append(servletUrl);
// Main UI link
html.append("<br><a href='/#!/settings/things/" + BINDING_ID + ":"
+ 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>");
// device list
for (Device device : this.account.getLastKnownDevices()) {
html.append("<tr><td>");
- html.append(StringEscapeUtils.escapeHtml(nullReplacement(device.accountName)));
+ html.append(HtmlEscape.escapeHtml4(nullReplacement(device.accountName)));
html.append("</td><td>");
- html.append(StringEscapeUtils.escapeHtml(nullReplacement(device.serialNumber)));
+ html.append(HtmlEscape.escapeHtml4(nullReplacement(device.serialNumber)));
html.append("</td><td>");
- html.append(StringEscapeUtils.escapeHtml(device.online ? "Online" : "Offline"));
+ html.append(HtmlEscape.escapeHtml4(device.online ? "Online" : "Offline"));
html.append("</td><td>");
Thing accountHandler = account.findThingBySerialNumber(device.serialNumber);
if (accountHandler != null) {
html.append("<a href='" + servletUrl + "/ids/?serialNumber="
+ URLEncoder.encode(device.serialNumber, "UTF8") + "'>"
- + StringEscapeUtils.escapeHtml(accountHandler.getLabel()) + "</a>");
+ + HtmlEscape.escapeHtml4(accountHandler.getLabel()) + "</a>");
} else {
html.append("<a href='" + servletUrl + "/ids/?serialNumber="
- + URLEncoder.encode(device.serialNumber, "UTF8") + "'>"
- + StringEscapeUtils.escapeHtml("Not defined") + "</a>");
+ + URLEncoder.encode(device.serialNumber, "UTF8") + "'>" + HtmlEscape.escapeHtml4("Not defined")
+ + "</a>");
}
html.append("</td><td>");
- html.append(StringEscapeUtils.escapeHtml(nullReplacement(device.deviceFamily)));
+ html.append(HtmlEscape.escapeHtml4(nullReplacement(device.deviceFamily)));
html.append("</td><td>");
- html.append(StringEscapeUtils.escapeHtml(nullReplacement(device.deviceType)));
+ html.append(HtmlEscape.escapeHtml4(nullReplacement(device.deviceType)));
html.append("</td><td>");
- html.append(StringEscapeUtils.escapeHtml(nullReplacement(device.deviceOwnerCustomerId)));
+ html.append(HtmlEscape.escapeHtml4(nullReplacement(device.deviceOwnerCustomerId)));
html.append("</td>");
html.append("</tr>");
}
private void handleDevices(HttpServletResponse resp, Connection connection)
throws IOException, URISyntaxException, InterruptedException {
- returnHtml(connection, resp,
- "<html>" + StringEscapeUtils.escapeHtml(connection.getDeviceListJson()) + "</html>");
+ returnHtml(connection, resp, "<html>" + HtmlEscape.escapeHtml4(connection.getDeviceListJson()) + "</html>");
}
private String nullReplacement(@Nullable String text) {
StringBuilder createPageStart(String title) {
StringBuilder html = new StringBuilder();
html.append("<html><head><title>"
- + 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("</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()) {
html.append(" - ");
- html.append(StringEscapeUtils.escapeHtml(title));
+ html.append(HtmlEscape.escapeHtml4(title));
}
html.append("</h1>");
return html;
private void createPageEndAndSent(HttpServletResponse resp, StringBuilder html) {
// account overview link
html.append("<br><a href='" + servletUrl + "/../' >");
- html.append(StringEscapeUtils.escapeHtml("Account overview"));
+ html.append(HtmlEscape.escapeHtml4("Account overview"));
html.append("</a><br>");
html.append("</body></html>");
private void renderCapabilities(Connection connection, Device device, StringBuilder html) {
html.append("<h2>Capabilities</h2>");
html.append("<table><tr><th align='left'>Name</th></tr>");
- device.getCapabilities().forEach(capability -> html.append("<tr><td>")
- .append(StringEscapeUtils.escapeHtml(capability)).append("</td></tr>"));
+ device.getCapabilities().forEach(
+ capability -> html.append("<tr><td>").append(HtmlEscape.escapeHtml4(capability)).append("</td></tr>"));
html.append("</table>");
}
private void renderMusicProviderIdChannel(Connection connection, StringBuilder html) {
- html.append("<h2>").append(StringEscapeUtils.escapeHtml("Channel " + CHANNEL_MUSIC_PROVIDER_ID))
- .append("</h2>");
+ html.append("<h2>").append(HtmlEscape.escapeHtml4("Channel " + CHANNEL_MUSIC_PROVIDER_ID)).append("</h2>");
html.append("<table><tr><th align='left'>Name</th><th align='left'>Value</th></tr>");
List<JsonMusicProvider> musicProviders = connection.getMusicProviders();
for (JsonMusicProvider musicProvider : musicProviders) {
&& !providerId.isEmpty() && "AVAILABLE".equals(musicProvider.availability) && displayName != null
&& !displayName.isEmpty()) {
html.append("<tr><td>");
- html.append(StringEscapeUtils.escapeHtml(displayName));
+ html.append(HtmlEscape.escapeHtml4(displayName));
html.append("</td><td>");
- html.append(StringEscapeUtils.escapeHtml(providerId));
+ html.append(HtmlEscape.escapeHtml4(providerId));
html.append("</td></tr>");
}
}
}
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();
String errorMessage = "No notifications sounds found";
try {
String providerSoundId = notificationSound.providerId + ":" + notificationSound.id;
html.append("<tr><td>");
- html.append(StringEscapeUtils.escapeHtml(notificationSound.displayName));
+ html.append(HtmlEscape.escapeHtml4(notificationSound.displayName));
html.append("</td><td>");
- html.append(StringEscapeUtils.escapeHtml(providerSoundId));
+ html.append(HtmlEscape.escapeHtml4(providerSoundId));
html.append("</td></tr>");
}
}
html.append("</table>");
} else {
- html.append(StringEscapeUtils.escapeHtml(errorMessage));
+ html.append(HtmlEscape.escapeHtml4(errorMessage));
}
}
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>");
JsonPlaylists playLists = null;
PlayList playList = innerLists[0];
if (playList != null && playList.playlistId != null && playList.title != null) {
html.append("<tr><td>");
- html.append(StringEscapeUtils.escapeHtml(nullReplacement(playList.title)));
+ html.append(HtmlEscape.escapeHtml4(nullReplacement(playList.title)));
html.append("</td><td>");
- html.append(StringEscapeUtils.escapeHtml(nullReplacement(playList.playlistId)));
+ html.append(HtmlEscape.escapeHtml4(nullReplacement(playList.playlistId)));
html.append("</td></tr>");
}
}
}
html.append("</table>");
} else {
- html.append(StringEscapeUtils.escapeHtml(errorMessage));
+ html.append(HtmlEscape.escapeHtml4(errorMessage));
}
}
}
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();
if (bluetoothStates == null) {
return;
html.append("<table><tr><th align='left'>Name</th><th align='left'>Value</th></tr>");
for (PairedDevice pairedDevice : pairedDeviceList) {
html.append("<tr><td>");
- html.append(StringEscapeUtils.escapeHtml(nullReplacement(pairedDevice.friendlyName)));
+ html.append(HtmlEscape.escapeHtml4(nullReplacement(pairedDevice.friendlyName)));
html.append("</td><td>");
- html.append(StringEscapeUtils.escapeHtml(nullReplacement(pairedDevice.address)));
+ html.append(HtmlEscape.escapeHtml4(nullReplacement(pairedDevice.address)));
html.append("</td></tr>");
}
html.append("</table>");
} else {
- html.append(StringEscapeUtils.escapeHtml("No bluetooth devices paired"));
+ html.append(HtmlEscape.escapeHtml4("No bluetooth devices paired"));
}
}
}
void returnError(HttpServletResponse resp, @Nullable String errorMessage) {
try {
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>");
} catch (IOException e) {
logger.info("Returning error message failed", e);