Source:
<code>public EList<Widget> renderWidget(Widget w, StringBuilder sb) throws RenderException { Switch s = (Switch) w; String snippetName = null; Item item; try { item = itemUIRegistry.getItem(w.getItem()); if (s.getMappings().size() == 0) { if (item instanceof RollershutterItem) { snippetName = "rollerblind"; } else if (item instanceof GroupItem && ((GroupItem) item).getBaseItem() instanceof RollershutterItem) { snippetName = "rollerblind"; } else { snippetName = "switch"; } } else { snippetName = "buttons"; } } catch (ItemNotFoundException e) { logger.warn("Cannot determine item type of '{}'", w.getItem(), e); snippetName = "switch"; } String snippet = getSnippet(snippetName); State state = itemUIRegistry.getState(w); snippet = preprocessSnippet(snippet, w); snippet = StringUtils.replace(snippet, "%count%", Integer.toString(s.getMappings().size())); if (s.getMappings().size() == 0) { if (state.equals(OnOffType.ON)) { snippet = snippet.replaceAll("%checked%", "checked=true"); } else { snippet = snippet.replaceAll("%checked%", ""); } } else { StringBuilder buttons = new StringBuilder(); for (Mapping mapping : s.getMappings()) { String button = getSnippet("button"); button = StringUtils.replace(button, "%item%", w.getItem()); <START> button = StringUtils.replace(button, "%cmd%", mapping.getCmd()); <END> button = StringUtils.replace(button, "%label%", mapping.getLabel() != null ? escapeHtml(mapping.getLabel()) : ""); if (s.getMappings().size() > 1 && state.toString().equals(mapping.getCmd())) { button = StringUtils.replace(button, "%class%", "mdl-button--accent"); } else { button = StringUtils.replace(button, "%class%", "mdl-button"); } buttons.append(button); } snippet = StringUtils.replace(snippet, "%buttons%", buttons.toString()); } snippet = processColor(w, snippet); sb.append(snippet); return null; }</code><technical_language>Also, StringEscapeUtils.escapeHTML is right choice - quotes backslashes need prepended \ resulting HTML attribute correct read Javascript</technical_language>

Target:
public EList<Widget> renderWidget(Widget w, StringBuilder sb) throws RenderException { Switch s = (Switch) w; String snippetName = null; Item item; try { item = itemUIRegistry.getItem(w.getItem()); if (s.getMappings().size() == 0) { if (item instanceof RollershutterItem) { snippetName = "rollerblind"; } else if (item instanceof GroupItem && ((GroupItem) item).getBaseItem() instanceof RollershutterItem) { snippetName = "rollerblind"; } else { snippetName = "switch"; } } else { snippetName = "buttons"; } } catch (ItemNotFoundException e) { logger.warn("Cannot determine item type of '{}'", w.getItem(), e); snippetName = "switch"; } String snippet = getSnippet(snippetName); State state = itemUIRegistry.getState(w); snippet = preprocessSnippet(snippet, w); snippet = StringUtils.replace(snippet, "%count%", Integer.toString(s.getMappings().size())); if (s.getMappings().size() == 0) { if (state.equals(OnOffType.ON)) { snippet = snippet.replaceAll("%checked%", "checked=true"); } else { snippet = snippet.replaceAll("%checked%", ""); } } else { StringBuilder buttons = new StringBuilder(); for (Mapping mapping : s.getMappings()) { String button = getSnippet("button"); button = StringUtils.replace(button, "%item%", w.getItem()); button = StringUtils.replace(button, "%cmd%", escapeHtml(mapping.getCmd())); button = StringUtils.replace(button, "%label%", mapping.getLabel() != null ? escapeHtml(mapping.getLabel()) : ""); if (s.getMappings().size() > 1 && state.toString().equals(mapping.getCmd())) { button = StringUtils.replace(button, "%class%", "mdl-button--accent"); } else { button = StringUtils.replace(button, "%class%", "mdl-button"); } buttons.append(button); } snippet = StringUtils.replace(snippet, "%buttons%", buttons.toString()); } snippet = processColor(w, snippet); sb.append(snippet); return null; }