/** * Return the HTML as a {@link SafeHtml} string. */ public SafeHtml asSafeHtml() { // End all open tags. endAllTags(); /* * sb is trusted because we only append trusted strings or escaped strings * to it. */ return SafeHtmlUtils.fromTrustedString(sb.toString()); }
/** * Creates an HTML panel with the specified HTML contents inside a DIV * element. Any element within this HTML that has a specified id can contain a * child widget. * The actual element that will hold this HTML isn't initialized until it is * needed. * * @param html the panel's HTML */ public RenderablePanel(@IsSafeHtml String html) { this(SafeHtmlUtils.fromTrustedString(html)); }
/** * Stamps an HTML element in such a way that it can be later found in the DOM tree. * To be used by {@link IsRenderable} objects built using {@link SafeHtml} directly, this assumes * the element to be stamped is the first found in the given {@link SafeHtml}. * Returns safeHtml untouched if it does not being with a tag. */ public SafeHtml stamp(SafeHtml safeHtml) { String html = safeHtml.asString().trim(); if (!html.startsWith("<")) { return safeHtml; } int endOfFirstTag = html.indexOf('>'); // TODO(rdcastro): Maybe add a DEV-only check to make sure endOfFirstTag != -1 if (html.charAt(endOfFirstTag - 1) == '/') { endOfFirstTag--; } StringBuilder htmlBuilder = new StringBuilder() .append(html.substring(0, endOfFirstTag)) .append(" id ='") .append(token) .append("'") .append(html.substring(endOfFirstTag)); return SafeHtmlUtils.fromTrustedString(htmlBuilder.toString()); }
/** * Inserts an attribute into the first tag found in a {@code safeHtml} template. * This method assumes that the {@code safeHtml} template begins with an open HTML tag. * {@code SafeHtml} templates produced by UiBinder always meet these conditions. * <p> * This method does not attempt to ensure {@code atributeName} and {@code attributeValue} * contain safe values. * * @returns the {@code safeHtml} template with "{@code attributeName}={@code attributeValue}" * inserted as an attribute of the first tag found */ protected static SafeHtml stampUiRendererAttribute(SafeHtml safeHtml, String attributeName, String attributeValue) { String html = safeHtml.asString(); int endOfFirstTag = html.indexOf(">"); assert endOfFirstTag > 1 : "Safe html template does not start with an HTML open tag"; if (html.charAt(endOfFirstTag - 1) == '/') { endOfFirstTag--; } html = html.substring(0, endOfFirstTag) + " " + attributeName + "=\"" + attributeValue + "\"" + html.substring(endOfFirstTag); return SafeHtmlUtils.fromTrustedString(html); }
/** * Get the {@link TableSectionElement} containing the children. * * @param tag the expected tag (tbody, tfoot, or thead) */ private static SafeHtml tableSectionToSafeHtml(TableSectionBuilder section, String tag) { if (!(section instanceof HtmlTableSectionBuilder)) { throw new IllegalArgumentException("Only HtmlTableSectionBuilder is supported at this time"); } // Strip the table section tags off of the tbody. HtmlTableSectionBuilder htmlSection = (HtmlTableSectionBuilder) section; String rawHtml = htmlSection.asSafeHtml().asString(); assert (tag.length()) == 5 : "Unrecognized tag: " + tag; assert rawHtml.startsWith("<" + tag + ">") : MALFORMED_HTML_SECTION; assert rawHtml.endsWith("</" + tag + ">") : MALFORMED_HTML_SECTION; rawHtml = rawHtml.substring(7, rawHtml.length() - 8); return SafeHtmlUtils.fromTrustedString(rawHtml); }
@Override public SafeHtml processHtml(SafeHtml html) { // If the widget is listening for load events, we modify the HTML to add the // load/error listeners. if (loadEventsInitialized && html != null) { String moduleName = GWT.getModuleName(); String listener = "__gwt_CellBasedWidgetImplLoadListeners[\"" + moduleName + "\"]();"; String htmlString = html.asString(); htmlString = htmlString.replaceAll("(<img)([\\s/>])", "<img onload='" + listener + "' onerror='" + listener + "'$2"); // We assert that the resulting string is safe html = SafeHtmlUtils.fromTrustedString(htmlString); } return html; }
/** * @see BidiFormatter#spanWrap(String, boolean, boolean) * * @param html The input html * @param dirReset Whether to append a trailing unicode bidi mark matching the * context direction, when needed, to prevent the possible garbling * of whatever may follow {@code html} * @return Input html after applying the above processing. */ public SafeHtml spanWrap(SafeHtml html, boolean dirReset) { return SafeHtmlUtils.fromTrustedString( spanWrapBase(html.asString(), true, dirReset)); }
/** * Sets the html string inside the caption by calling its * {@link #setHTML(SafeHtml)} method. Only known safe HTML should be inserted * in here. * * Use {@link #setWidget(Widget)} to set the contents inside the * {@link DialogBox}. * * @param html the object's new HTML */ public void setHTML(@IsSafeHtml String html) { caption.setHTML(SafeHtmlUtils.fromTrustedString(html)); }
/** * @see BidiFormatter#unicodeWrap(String, boolean, boolean) * * @param html The input html * @param dirReset Whether to append a trailing unicode bidi mark matching the * context direction, when needed, to prevent the possible garbling * of whatever may follow {@code html} * @return Input html after applying the above processing. */ public SafeHtml unicodeWrap(SafeHtml html, boolean dirReset) { return SafeHtmlUtils.fromTrustedString( unicodeWrapBase(html.asString(), true, dirReset)); }
/** * @see BidiFormatter#spanWrap(String, boolean, boolean) * * @param str The input string * @param dirReset Whether to append a trailing unicode bidi mark matching the * context direction, when needed, to prevent the possible garbling * of whatever may follow {@code str} * @return Input string after applying the above processing. */ @SuppressIsSafeHtmlCastCheck public SafeHtml spanWrap(String str, boolean dirReset) { // This is safe since spanWrapBase escapes plain-text input. return SafeHtmlUtils.fromTrustedString(spanWrapBase(str, false, dirReset)); }
/** * @see BidiFormatter#unicodeWrapWithKnownDir( * com.google.gwt.i18n.client.HasDirection.Direction, String, boolean, boolean) * * @param dir {@code html}'s direction * @param html The input html * @param dirReset Whether to append a trailing unicode bidi mark matching the * context direction, when needed, to prevent the possible garbling * of whatever may follow {@code html} * @return Input html after applying the above processing. */ public SafeHtml unicodeWrapWithKnownDir(Direction dir, SafeHtml html, boolean dirReset) { return SafeHtmlUtils.fromTrustedString( unicodeWrapWithKnownDirBase(dir, html.asString(), true, dirReset)); }
/** * @see BidiFormatter#spanWrapWithKnownDir( * com.google.gwt.i18n.client.HasDirection.Direction, String, boolean, boolean) * * @param dir {@code html}'s direction * @param html The input html * @param dirReset Whether to append a trailing unicode bidi mark matching the * context direction, when needed, to prevent the possible garbling * of whatever may follow {@code html} * @return Input html after applying the above processing. */ public SafeHtml spanWrapWithKnownDir(Direction dir, SafeHtml html, boolean dirReset) { return SafeHtmlUtils.fromTrustedString( spanWrapWithKnownDirBase(dir, html.asString(), true, dirReset)); }
/** * @see BidiFormatter#spanWrapWithKnownDir( * com.google.gwt.i18n.client.HasDirection.Direction, String, boolean, boolean) * * @param dir {@code str}'s direction * @param str The input string * @param dirReset Whether to append a trailing unicode bidi mark matching the * context direction, when needed, to prevent the possible garbling * of whatever may follow {@code str} * @return Input string after applying the above processing. */ @SuppressIsSafeHtmlCastCheck public SafeHtml spanWrapWithKnownDir(Direction dir, String str, boolean dirReset) { // This is safe since spanWrapWithKnownDirBase escapes plain-text input. return SafeHtmlUtils.fromTrustedString( spanWrapWithKnownDirBase(dir, str, false, dirReset)); }
/** * Get the HTML representation of the sort icon. These are loaded lazily so * the compiler has a chance to strip this method, and the icon source code, * if the user overrides renderHeader. * * @param isAscending true for the ascending icon, false for descending * @return the rendered HTML */ private SafeHtml getSortIcon(boolean isAscending) { if (isAscending) { if (sortAscIconHtml == null) { AbstractImagePrototype proto = AbstractImagePrototype.create(table.getResources().sortAscending()); sortAscIconHtml = SafeHtmlUtils.fromTrustedString(proto.getHTML()); } return sortAscIconHtml; } else { if (sortDescIconHtml == null) { AbstractImagePrototype proto = AbstractImagePrototype.create(table.getResources().sortDescending()); sortDescIconHtml = SafeHtmlUtils.fromTrustedString(proto.getHTML()); } return sortDescIconHtml; } } }
openTag.append(" tabindex=\"" + tabIndex + "\" "); openTag.append(attributes.toString()).append(">"); sb.append(SafeHtmlUtils.fromTrustedString(openTag.toString())); sb.append(content); sb.appendHtmlConstant("</button>");
@Override public void render(Context context, ComparableImageResource value, SafeHtmlBuilder sb) { if (value != null) { // The template will sanitize the URI. sb.append(SafeHtmlUtils.fromTrustedString(value.getImageHTML())); } } }
@Override public void render( Context context, Analysis analysis, SafeHtmlBuilder sb ) { sb.append( SafeHtmlUtils.fromTrustedString( analysis.toHtmlString() ) ); }
@Override public SafeHtml getValue(T object) { ImageResource image = getImage(object); return (image == null) ? null : SafeHtmlUtils.fromTrustedString(AbstractImagePrototype.create(image).getHTML()); }
public static SafeHtml parseCode(String code) { SafeHtmlBuilder builder = new SafeHtmlBuilder(); String[] splitted = code.replaceAll("\\\\s", " ").split("\\\\n\\s?"); String[] arr$ = splitted; int len$ = splitted.length; for (int i$ = 0; i$ < len$; ++i$) { String s = arr$[i$]; builder.append(SafeHtmlUtils.fromTrustedString(SafeHtmlUtils.htmlEscapeAllowEntities(s))); builder.appendHtmlConstant("<br>"); } return builder.toSafeHtml(); }
private SafeHtml formatHeader(Month month) { DateWrapper date = new DateWrapper(month.getYear(), month.getMonth() - 1, 1); String header = monthFormat.format(date.asDate()); if (locked.apply(month)) { header = IconImageBundle.ICONS.lockedPeriodSmall().getHTML() + " " + header; } return SafeHtmlUtils.fromTrustedString(header); }