List of usage examples for com.google.gwt.safehtml.shared SafeHtmlUtils htmlEscape
public static String htmlEscape(String s)
From source file:com.google.testing.testify.risk.frontend.client.view.impl.ProjectSettingsViewImpl.java
License:Apache License
/** * Handler for the updateProjectInfoButton's click event. *//* w w w . j a v a 2 s . c o m*/ @UiHandler("updateProjectInfoButton") protected void onUpdateProjectInfoButtonClicked(ClickEvent event) { savedPanel.setVisible(false); updateProjectInfoButton.setEnabled(false); if (presenter != null) { if (deleteProjectCheckBox.getValue()) { presenter.removeProject(); reloadPage(); } else { final List<String> newOwners = StringUtil.csvToList(projectOwnersTextBox.getText()); final List<String> newEditors = StringUtil.csvToList(projectEditorsTextArea.getText()); final List<String> newViewers = StringUtil.csvToList(projectViewersTextArea.getText()); if (newOwners.size() < 1) { Window.alert("Error: The project must have at least one owner."); return; } StringBuilder warning = new StringBuilder(); List<String> difference = StringUtil.subtractList(newOwners, currentOwners); if (difference.size() > 0) { warning.append("<br><br><b>Added owners:</b> "); warning.append(SafeHtmlUtils.htmlEscape(StringUtil.listToCsv(difference))); } difference = StringUtil.subtractList(currentOwners, newOwners); if (difference.size() > 0) { warning.append("<br><br><b>Removed owners:</b> "); warning.append(SafeHtmlUtils.htmlEscape(StringUtil.listToCsv(difference))); } difference = StringUtil.subtractList(newEditors, currentEditors); if (difference.size() > 0) { warning.append("<br><br><b>Added editors:</b> "); warning.append(SafeHtmlUtils.htmlEscape(StringUtil.listToCsv(difference))); } difference = StringUtil.subtractList(currentEditors, newEditors); if (difference.size() > 0) { warning.append("<br><br><b>Removed editors:</b> "); warning.append(SafeHtmlUtils.htmlEscape(StringUtil.listToCsv(difference))); } difference = StringUtil.subtractList(newViewers, currentViewers); if (difference.size() > 0) { warning.append("<br><br><b>Added viewers:</b> "); warning.append(SafeHtmlUtils.htmlEscape(StringUtil.listToCsv(difference))); } difference = StringUtil.subtractList(currentViewers, newViewers); if (difference.size() > 0) { warning.append("<br><br><b>Removed viewers:</b> "); warning.append(SafeHtmlUtils.htmlEscape(StringUtil.listToCsv(difference))); } // If there's a warning to save, then display it and require confirmation before saving. // Otherwise, just save. if (warning.length() > 0) { StandardDialogBox box = new StandardDialogBox(); box.setTitle("Permission Changes"); box.add(new HTML("You are changing some of the permissions for this project." + warning.toString() + "<br><br>")); box.addDialogClosedHandler(new DialogClosedHandler() { @Override public void onDialogClosed(DialogClosedEvent event) { if (event.getResult().equals(DialogResult.OK)) { presenter.onUpdateProjectInfoClicked(projectName.getText(), projectDescription.getText(), newOwners, newEditors, newViewers, projectIsPublicCheckBox.getValue()); currentOwners = newOwners; currentEditors = newEditors; currentViewers = newViewers; } else { updateProjectInfoButton.setEnabled(true); } } }); StandardDialogBox.showAsDialog(box); } else { presenter.onUpdateProjectInfoClicked(projectName.getText(), projectDescription.getText(), newOwners, newEditors, newViewers, projectIsPublicCheckBox.getValue()); } } } }
From source file:com.googlecode.mgwt.ui.client.widget.celllist.BasicCell.java
License:Apache License
@Override public void render(SafeHtmlBuilder safeHtmlBuilder, final T model) { safeHtmlBuilder.append(TEMPLATE.content(styleName, SafeHtmlUtils.htmlEscape(getDisplayString(model)))); }
From source file:com.kiahu.sample.client.view.tablet.BasicCell.java
License:Open Source License
@Override public void render(SafeHtmlBuilder safeHtmlBuilder, final T model) { safeHtmlBuilder.append(TEMPLATE.content("", SafeHtmlUtils.htmlEscape(getDisplayString(model)))); }
From source file:com.mattbertolini.hermes.MessagesProxy.java
License:Open Source License
private Object parseMessage(Method method, Object[] args) { String messageName;//from w w w . j av a 2 s . co m Key keyAnnotation = method.getAnnotation(Key.class); if (keyAnnotation == null) { messageName = method.getName(); } else { messageName = keyAnnotation.value(); } List<String> formsNames = new LinkedList<String>(); Annotation[][] parameterAnnotations = method.getParameterAnnotations(); Class<?>[] parameterTypes = method.getParameterTypes(); for (int i = 0; i < parameterTypes.length; i++) { Annotation[] annotations = parameterAnnotations[i]; Class<?> type = parameterTypes[i]; for (Annotation annotation : annotations) { if (PluralCount.class.isAssignableFrom(annotation.annotationType()) && (int.class.isAssignableFrom(type) || Integer.class.isAssignableFrom(type) || short.class.isAssignableFrom(type) || Short.class.isAssignableFrom(type))) { Number num = (Number) args[i]; Plural plural; // Check for a custom plural rule. PluralCount pc = (PluralCount) annotation; Class<? extends PluralRule> pluralRuleClass = pc.value(); if (!pluralRuleClass.isInterface() && PluralRule.class.isAssignableFrom(pluralRuleClass)) { PluralRule customRule = this.instantiateCustomPluralRuleClass(pluralRuleClass); plural = CustomPlural.fromNumber(customRule, num.intValue()); } else { plural = GwtPlural.fromNumber(this.pluralRules, num.doubleValue()); } formsNames.add(plural.getGwtValue()); } else if (Select.class.isAssignableFrom(annotation.annotationType())) { if (Enum.class.isAssignableFrom(type)) { Enum<?> enumConstant = (Enum<?>) args[i]; String name; if (enumConstant == null) { name = "other"; } else { name = enumConstant.name(); } formsNames.add(name); } else if (String.class.isAssignableFrom(type)) { String str = (String) args[i]; if (str == null) { str = "other"; } formsNames.add(str); } else if (type.isPrimitive() && (int.class.isAssignableFrom(type) || long.class.isAssignableFrom(type) || float.class.isAssignableFrom(type) || short.class.isAssignableFrom(type) || double.class.isAssignableFrom(type))) { Number num = (Number) args[i]; formsNames.add(num.toString()); } } } } String patternName = this.buildPatternName(messageName, formsNames); String pattern = this.getProperties().getProperty(patternName); if (pattern == null) { Map<String, String> altMsgMap = this.buildAlternateMessageMap(messageName, method); pattern = altMsgMap.get(patternName); if (pattern == null) { pattern = this.getProperties().getProperty(messageName); if (pattern == null) { DefaultMessage defaultMessage = method.getAnnotation(DefaultMessage.class); if (defaultMessage != null) { pattern = defaultMessage.value(); } else { throw new RuntimeException("No message found for key " + messageName); } } } } MessageFormat formatter = new MessageFormat(pattern, this.getLocale()); Object retVal; if (method.getReturnType().equals(SafeHtml.class)) { Object[] safeArgs = null; if (args != null) { safeArgs = new Object[args.length]; for (int i = 0; i < args.length; i++) { Object arg = args[i]; Class<?> argType = parameterTypes[i]; if (SafeHtml.class.isAssignableFrom(argType)) { SafeHtml sh = (SafeHtml) arg; safeArgs[i] = sh.asString(); } else if (Number.class.isAssignableFrom(argType) || Date.class.isAssignableFrom(argType)) { // Because of the subformat pattern of dates and // numbers, we cannot escape them. safeArgs[i] = arg; } else { safeArgs[i] = SafeHtmlUtils.htmlEscape(arg.toString()); } } } String formattedString = formatter.format(safeArgs, new StringBuffer(), null).toString(); // Would rather use fromSafeConstant() but doesn't work on server. retVal = SafeHtmlUtils.fromTrustedString(formattedString); } else { retVal = formatter.format(args, new StringBuffer(), null).toString(); } return retVal; }
From source file:com.moesol.gwt.maps.client.controls.OutlinedLabel.java
License:Open Source License
/** * Set the text value of the label./*w w w .jav a 2s. c o m*/ * @param value */ public void setText(String value) { String safeValue = SafeHtmlUtils.htmlEscape(value); text.setInnerHTML(safeValue); top.setInnerHTML(safeValue); right.setInnerHTML(safeValue); bottom.setInnerHTML(safeValue); left.setInnerHTML(safeValue); topLeft.setInnerHTML(safeValue); bottomRight.setInnerHTML(safeValue); topRight.setInnerHTML(safeValue); bottomLeft.setInnerHTML(safeValue); }
From source file:com.moesol.gwt.maps.client.controls.OutlinedLabelLegacy.java
License:Open Source License
/** * Set the text value of the label./* w ww. j a v a 2 s . c o m*/ * @param value */ public void setText(String value) { String safeValue = SafeHtmlUtils.htmlEscape(value); text.setHTML(safeValue); top.setHTML(safeValue); right.setHTML(safeValue); bottom.setHTML(safeValue); left.setHTML(safeValue); topLeft.setHTML(safeValue); bottomRight.setHTML(safeValue); topRight.setHTML(safeValue); bottomLeft.setHTML(safeValue); }
From source file:com.msco.mil.client.com.sencha.gxt.explorer.client.dnd.BasicDndExample.java
License:sencha.com license
private void addSources(FlowLayoutContainer container) { for (int i = 0; i < 5; i++) { final SafeHtmlBuilder builder = new SafeHtmlBuilder(); builder.appendHtmlConstant("<div style=\"border:1px solid #ddd;cursor:default\" class=\"" + SafeHtmlUtils.htmlEscape(ExampleStyles.get().paddedText()) + "\">"); builder.appendHtmlConstant("Drag Me " + i); builder.appendHtmlConstant("</div>"); final HTML html = new HTML(builder.toSafeHtml()); container.add(html, new MarginData(3)); DragSource source = new DragSource(html) { @Override/*from w ww .j ava 2 s .c o m*/ protected void onDragStart(DndDragStartEvent event) { super.onDragStart(event); // by default drag is allowed event.setData(html); event.getStatusProxy().update(builder.toSafeHtml()); } }; // group is optional source.setGroup("test"); } }
From source file:com.sencha.gxt.core.client.util.Format.java
License:sencha.com license
/** * Convert certain characters (&, <, >, and ') to their HTML character * equivalents for literal display in web pages. Delegates to * {@link URL#encode(String)}./*w w w . j a va 2 s . c om*/ * * @param value the value * @return the encoded value */ public static String htmlEncode(String value) { return SafeHtmlUtils.htmlEscape(value); }
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 w w w . j ava2 s.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.colorpalette.ColorPaletteBaseAppearance.java
License:sencha.com license
@Override public void render(Context context, String value, String[] colors, String[] labels, SafeHtmlBuilder result) { result.appendHtmlConstant("<table class=\"" + style.colorPalette() + "\">"); int mark = 0; int rows = (colors.length + (columnCount - 1)) / columnCount; for (int i = 0; i < rows; i++) { result.appendHtmlConstant("<tr>"); for (int j = 0; j < columnCount && mark < colors.length; j++) { String c = colors[mark]; String label = labels[mark]; SafeHtml cellTemplate = template.cellTemplate(style, label, XDOM.getUniqueId(), i, j, c, SafeStylesUtils//from ww w. ja va 2 s . co m .fromTrustedString("background-color: #" + SafeHtmlUtils.htmlEscape(c) + ";"), c.equals(value) ? style.selected() : ""); result.append(cellTemplate); mark++; } result.appendHtmlConstant("</tr>"); } result.appendHtmlConstant("</table>"); }