List of usage examples for com.google.gwt.safehtml.shared SafeHtmlUtils fromTrustedString
public static SafeHtml fromTrustedString(String s)
From source file:com.ritchey.attendance.client.view.ClickImageResourceCell.java
License:Apache License
@Override public void render(Context context, ImageResource value, SafeHtmlBuilder sb) { if (value != null) { SafeHtml html = SafeHtmlUtils.fromTrustedString(AbstractImagePrototype.create(value).getHTML()); sb.append(html);/*from w w w .java2 s. c o m*/ } }
From source file:com.ritchey.attendance.client.view.ClickImageResourceTextCell.java
License:Apache License
@Override public void render(Context context, ImageResourceText value, SafeHtmlBuilder sb) { if (value != null) { String text = ""; if (value.value != null) { text = "<div>" + value.value + "</div>"; }//from ww w. j a v a 2 s . c o m SafeHtml html = SafeHtmlUtils .fromTrustedString(AbstractImagePrototype.create(value.image).getHTML() + text); sb.append(html); } }
From source file:com.ritchey.attendance.client.view.ClickTextCellWithSecondary.java
License:Apache License
@Override public void render(Context context, String value, SafeHtmlBuilder sb) { if (value != null) {// String x = ""; if (getClazz() != null) { x = " class='" + getClazz() + "' "; }/*from w w w.j av a 2 s. c o m*/ String y = ""; if (getSecondaryClazz() != null) { y = " class='" + getSecondaryClazz() + "' "; } String values[] = value.split("~"); if (values.length == 1) { values[1] = ""; } SafeHtml html = SafeHtmlUtils.fromTrustedString( "<div" + x + ">" + values[0] + "</div><div" + y + ">" + values[1] + "</div>" + ""); sb.append(html); } }
From source file:com.seanchenxi.gwt.serenity.client.view.impl.DiscussionViewImpl.java
License:Apache License
public void setMessage(boolean isPending, String message) { SafeHtml shtml;//from ww w . j av a 2s . c o m if (isPending) { SafeHtmlBuilder shb = new SafeHtmlBuilder(); shb.appendHtmlConstant("<p class=\"").appendHtmlConstant(getStyle().pendingDiscussion()) .appendHtmlConstant("\">") .appendHtmlConstant(SerenityResources.MSG.msg_yourCommentIsAwaitingMod()) .appendHtmlConstant("</p>").appendHtmlConstant(message); shtml = shb.toSafeHtml(); } else { shtml = SafeHtmlUtils.fromTrustedString(message); } content.setHTML(shtml); }
From source file:com.sencha.gxt.core.shared.ExpandedHtmlSanitizer.java
License:sencha.com license
/** * HTML-sanitizes a string./*from www .jav a2 s. co m*/ * * <p> * The input string is processed as described above. The result of sanitizing * the string is guaranteed to be safe to use (with respect to XSS * vulnerabilities) in HTML contexts, and is returned as an instance of the * {@link SafeHtml} type. * * @param html the input String * @return a sanitized SafeHtml instance */ public static SafeHtml sanitizeHtml(String html) { if (html == null) { throw new NullPointerException("html is null"); } return SafeHtmlUtils.fromTrustedString(simpleSanitize(html)); }
From source file:com.sencha.gxt.explorer.client.grid.WordWrapGridExample.java
License:sencha.com license
private SafeHtml wrapString(String untrustedString) { SafeHtml escapedString = SafeHtmlUtils.fromString(untrustedString); SafeHtml safeHtml = SafeHtmlUtils .fromTrustedString("<span style='white-space: normal;'>" + escapedString.asString() + "</span>"); return safeHtml; }
From source file:com.sencha.gxt.theme.base.client.button.ButtonCellDefaultAppearance.java
License:sencha.com license
@Override public void render(final ButtonCell<C> cell, Context context, C value, SafeHtmlBuilder sb) { String constantHtml = cell.getHTML(); boolean hasConstantHtml = constantHtml != null && constantHtml.length() != 0; boolean isBoolean = value != null && value instanceof Boolean; // is a boolean always a toggle button? SafeHtml valueHtml = SafeHtmlUtils.fromTrustedString(hasConstantHtml ? cell.getText() : (value != null && !isBoolean) ? SafeHtmlUtils.htmlEscape(value.toString()) : ""); ImageResource icon = cell.getIcon(); IconAlign iconAlign = cell.getIconAlign(); String cls = style.button();/*from www . j a va 2s . c o m*/ String arrowCls = ""; if (cell.getMenu() != null) { if (cell instanceof SplitButtonCell) { switch (cell.getArrowAlign()) { case RIGHT: arrowCls = style.split(); break; case BOTTOM: arrowCls = style.splitBottom(); break; default: // empty } } else { switch (cell.getArrowAlign()) { case RIGHT: arrowCls = style.arrow(); break; case BOTTOM: arrowCls = style.arrowBottom(); break; } } } ButtonScale scale = cell.getScale(); switch (scale) { case SMALL: cls += " " + style.small(); break; case MEDIUM: cls += " " + style.medium(); break; case LARGE: cls += " " + style.large(); break; default: // empty } SafeStylesBuilder stylesBuilder = new SafeStylesBuilder(); int width = -1; if (cell.getWidth() != -1) { int w = cell.getWidth(); if (w < cell.getMinWidth()) { w = cell.getMinWidth(); } stylesBuilder.appendTrustedString("width:" + w + "px;"); cls += " " + style.hasWidth() + " x-has-width"; width = w; } else { if (cell.getMinWidth() != -1) { TextMetrics.get().bind(style.text()); int length = TextMetrics.get().getWidth(valueHtml); length += 6; // frames if (icon != null) { switch (iconAlign) { case LEFT: case RIGHT: length += icon.getWidth(); break; default: // empty } } if (cell.getMinWidth() > length) { stylesBuilder.appendTrustedString("width:" + cell.getMinWidth() + "px;"); cls += " " + style.hasWidth() + " x-has-width"; width = cell.getMinWidth(); } } } final int height = cell.getHeight(); if (height != -1) { stylesBuilder.appendTrustedString("height:" + height + "px;"); } if (icon != null) { switch (iconAlign) { case TOP: arrowCls += " " + style.iconTop(); break; case BOTTOM: arrowCls += " " + style.iconBottom(); break; case LEFT: arrowCls += " " + style.iconLeft(); break; case RIGHT: arrowCls += " " + style.iconRight(); break; } } else { arrowCls += " " + style.noIcon(); } // toggle button if (value == Boolean.TRUE) { cls += " " + frame.pressedClass(); } sb.append(templates.outer(cls, new SafeStylesBuilder().toSafeStyles())); SafeHtmlBuilder inside = new SafeHtmlBuilder(); String innerWrap = arrowCls; inside.appendHtmlConstant("<div class='" + innerWrap + "'>"); inside.appendHtmlConstant("<table cellpadding=0 cellspacing=0 class='" + style.mainTable() + "'>"); boolean hasText = valueHtml != null && !valueHtml.equals(""); if (icon != null) { switch (iconAlign) { case LEFT: inside.appendHtmlConstant("<tr>"); writeIcon(inside, icon, height); if (hasText) { int w = width - (icon != null ? icon.getWidth() : 0) - 4; writeValue(inside, valueHtml, w, height); } inside.appendHtmlConstant("</tr>"); break; case RIGHT: inside.appendHtmlConstant("<tr>"); if (hasText) { int w = width - (icon != null ? icon.getWidth() : 0) - 4; writeValue(inside, valueHtml, w, height); } writeIcon(inside, icon, height); inside.appendHtmlConstant("</tr>"); break; case TOP: inside.appendHtmlConstant("<tr>"); writeIcon(inside, icon, height); inside.appendHtmlConstant("</tr>"); if (hasText) { inside.appendHtmlConstant("<tr>"); writeValue(inside, valueHtml, width, height); inside.appendHtmlConstant("</tr>"); } break; case BOTTOM: if (hasText) { inside.appendHtmlConstant("<tr>"); writeValue(inside, valueHtml, width, height); inside.appendHtmlConstant("</tr>"); } inside.appendHtmlConstant("<tr>"); writeIcon(inside, icon, height); inside.appendHtmlConstant("</tr>"); break; } } else { inside.appendHtmlConstant("<tr>"); if (valueHtml != null) { writeValue(inside, valueHtml, width, height); } inside.appendHtmlConstant("</tr>"); } inside.appendHtmlConstant("</table>"); inside.appendHtmlConstant("</div>"); frame.render(sb, new Frame.FrameOptions(0, CommonStyles.get().noFocusOutline(), stylesBuilder.toSafeStyles()), inside.toSafeHtml()); sb.appendHtmlConstant("</div>"); }
From source file:com.sencha.gxt.theme.base.client.field.TriggerFieldDefaultAppearance.java
License:sencha.com license
/** * Helper method to render the input in the trigger field. *//*ww w.jav a 2 s .c o m*/ protected void renderInput(SafeHtmlBuilder shb, String value, SafeStyles inputStyles, FieldAppearanceOptions options) { // Deliberately using a StringBuilder, not SafeHtmlBuilder, as each append isn't adding // complete elements, but building up this single element, one attribute at a time. StringBuilder sb = new StringBuilder(); sb.append("<input "); if (options.isDisabled()) { sb.append("disabled=true "); } if (options.getName() != null) { // if set, escape the name property so it is a valid attribute sb.append("name='").append(SafeHtmlUtils.htmlEscape(options.getName())).append("' "); } if (options.isReadonly() || !options.isEditable()) { sb.append("readonly "); } if (inputStyles != null) { sb.append("style='").append(inputStyles.asString()).append("' "); } sb.append("class='").append(getStyle().field()).append(" ").append(getStyle().text()); String placeholder = options.getEmptyText() != null ? " placeholder='" + SafeHtmlUtils.htmlEscape(options.getEmptyText()) + "' " : ""; if (value.equals("") && options.getEmptyText() != null) { sb.append(" ").append(getStyle().empty()); if (GXT.isIE8() || GXT.isIE9()) { value = options.getEmptyText(); } } if (!options.isEditable()) { sb.append(" ").append(getStyle().noedit()); } sb.append("' "); sb.append(placeholder); //escaping the value string so it is a valid attribute sb.append("type='text' value='").append(SafeHtmlUtils.htmlEscape(value)).append("'/>"); // finally, converting stringbuilder into a SafeHtml instance and appending it // to the buidler we were given shb.append(SafeHtmlUtils.fromTrustedString(sb.toString())); }
From source file:com.sencha.gxt.theme.base.client.tabs.TabPanelBaseAppearance.java
License:sencha.com license
@Override public void createScrollers(XElement parent) { int h = getStripWrap(parent).getOffsetHeight(); SafeHtml html = SafeHtmlUtils.fromTrustedString("<div class='" + style.tabScrollerLeft() + "'></div>"); XElement scrollLeft = getBar(parent).insertFirst(html); scrollLeft.setId(XDOM.getUniqueId()); scrollLeft.setHeight(h);//from ww w . j av a 2 s . c om html = SafeHtmlUtils.fromTrustedString("<div class='" + style.tabScrollerRight() + "'></div>"); XElement scrollRight = getBar(parent).insertFirst(html); scrollRight.setId(XDOM.getUniqueId()); scrollRight.setHeight(h); }
From source file:com.sencha.gxt.theme.base.client.tree.TreeBaseAppearance.java
License:sencha.com license
@Override public XElement onJointChange(XElement node, XElement jointElement, Joint joint, TreeStyle ts) { Element e;//from www . j a va2s . c o m switch (joint) { case COLLAPSED: e = getImage(ts.getJointCloseIcon() == null ? resources.jointCollapsedIcon() : ts.getJointCloseIcon()); break; case EXPANDED: e = getImage(ts.getJointOpenIcon() == null ? resources.jointExpandedIcon() : ts.getJointOpenIcon()); break; default: e = XDOM.create(SafeHtmlUtils .fromTrustedString("<img src=\"" + GXT.getBlankImageUrl() + "\" width=\"16px\"/>")); } e.addClassName(style.joint()); e = (Element) node.getFirstChild().insertBefore(e, jointElement); jointElement.removeFromParent(); return e.cast(); }