List of usage examples for com.google.gwt.safehtml.shared SafeHtmlUtils htmlEscape
public static String htmlEscape(String s)
From source file:com.sencha.gxt.theme.base.client.field.TextAreaDefaultAppearance.java
License:sencha.com license
@Override public void render(SafeHtmlBuilder sb, String value, FieldAppearanceOptions options) { int width = options.getWidth(); int height = options.getHeight(); boolean empty = false; String name = options.getName() != null ? " name='" + options.getName() + "' " : ""; String disabled = options.isDisabled() ? " disabled=true" : ""; String ro = options.isReadonly() ? " readonly" : ""; String placeholder = options.getEmptyText() != null ? " placeholder='" + SafeHtmlUtils.htmlEscape(options.getEmptyText()) + "' " : ""; if ((value == null || value.equals("")) && options.getEmptyText() != null) { if (GXT.isIE8() || GXT.isIE9()) { value = options.getEmptyText(); }/*from www . j a va 2s.c o m*/ empty = true; } if (width == -1) { width = 150; } String inputStyles = ""; String wrapStyles = ""; Size adjusted = adjustTextAreaSize(width, height); if (width != -1) { wrapStyles += "width:" + width + "px;"; width = adjusted.getWidth(); inputStyles += "width:" + width + "px;"; } if (height != -1) { height = adjusted.getHeight(); inputStyles += "height: " + height + "px;"; } String cls = style.area() + " " + style.field(); if (empty) { cls += " " + style.empty(); } if (options instanceof TextAreaCellOptions) { TextAreaCellOptions opts = (TextAreaCellOptions) options; inputStyles += "resize:" + opts.getResizable().name().toLowerCase() + ";"; } sb.appendHtmlConstant("<div style='" + wrapStyles + "' class='" + style.wrap() + "'>"); sb.appendHtmlConstant("<textarea " + name + disabled + " style='" + inputStyles + "' type='text' class='" + cls + "'" + ro + placeholder + ">"); sb.append(SafeHtmlUtils.fromString(value)); sb.appendHtmlConstant("</textarea></div>"); }
From source file:com.sencha.gxt.theme.base.client.field.TextFieldDefaultAppearance.java
License:sencha.com license
@Override public void render(SafeHtmlBuilder sb, String type, String value, FieldAppearanceOptions options) { String inputStyles = ""; String wrapStyles = ""; int width = options.getWidth(); String name = options.getName() != null ? " name='" + options.getName() + "' " : ""; String disabled = options.isDisabled() ? "disabled=true" : ""; String placeholder = options.getEmptyText() != null ? " placeholder='" + SafeHtmlUtils.htmlEscape(options.getEmptyText()) + "' " : ""; boolean empty = false; if ((value == null || value.equals("")) && options.getEmptyText() != null) { if (GXT.isIE8() || GXT.isIE9()) { value = options.getEmptyText(); }/* w ww .j a va2 s .co m*/ empty = true; } if (width != -1) { wrapStyles += "width:" + width + "px;"; width = adjustTextAreaWidth(width); inputStyles += "width:" + width + "px;"; } String cls = style.text() + " " + style.field(); if (empty) { cls += " " + style.empty(); } String ro = options.isReadonly() ? " readonly" : ""; value = SafeHtmlUtils.htmlEscape(value); sb.appendHtmlConstant("<div style='" + wrapStyles + "' class='" + style.wrap() + "'>"); sb.appendHtmlConstant("<input " + name + disabled + " value='" + value + "' style='" + inputStyles + "' type='" + type + "' class='" + cls + "'" + ro + placeholder + ">"); 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. */// w w w . j a v a 2 s. co 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.field.TwinTriggerFieldDefaultAppearance.java
License:sencha.com license
@Override public void render(SafeHtmlBuilder sb, String value, FieldAppearanceOptions options) { int width = options.getWidth(); boolean hideTrigger = options.isHideTrigger(); String name = options.getName() != null ? " name='" + options.getName() + "' " : ""; String disabled = options.isDisabled() ? "disabled=true" : ""; if (width == -1) { width = 150;/*from www . j av a 2 s. c om*/ } String inputStyles = ""; String wrapStyles = ""; if (width != -1) { wrapStyles += "width:" + width + "px;"; // 6px margin, 2px border width -= 8; if (!hideTrigger) { width -= resources.triggerArrow().getWidth(); } inputStyles += "width:" + width + "px;"; } String cls = style.field() + " " + style.text(); String placeholder = options.getEmptyText() != null ? " placeholder='" + SafeHtmlUtils.htmlEscape(options.getEmptyText()) + "' " : ""; if (value.equals("") && options.getEmptyText() != null) { cls += " " + style.empty(); if (GXT.isIE8() || GXT.isIE9()) { value = options.getEmptyText(); } } if (!options.isEditable()) { cls += " " + getStyle().noedit(); } String ro = options.isReadonly() || !options.isEditable() ? " readonly " : " "; String input = "<input " + name + disabled + ro + placeholder + " style='" + inputStyles + "' type='text' value='" + value + "' class='" + cls + "'/>"; sb.appendHtmlConstant("<div style='" + wrapStyles + "' class='" + style.wrap() + "'>"); if (!options.isHideTrigger()) { sb.appendHtmlConstant("<table width=100% cellpadding=0 cellspacing=0><tr><td>"); sb.appendHtmlConstant(input); sb.appendHtmlConstant("</td>"); sb.appendHtmlConstant("<td>"); sb.appendHtmlConstant("<div class='" + style.trigger() + "'></div>"); sb.appendHtmlConstant("<div class='" + style.twinTrigger() + "'></div>"); sb.appendHtmlConstant("</td></table>"); } else { sb.appendHtmlConstant(input); } sb.appendHtmlConstant("</div>"); }
From source file:com.sencha.gxt.theme.base.client.tree.TreeBaseAppearance.java
License:sencha.com license
@Override public void renderNode(SafeHtmlBuilder sb, String id, SafeHtml text, TreeStyle ts, ImageResource icon, boolean checkable, CheckState checked, Joint joint, int level, TreeViewRenderMode renderMode) { if (renderMode == TreeViewRenderMode.ALL || renderMode == TreeViewRenderMode.BUFFER_WRAP) { sb.appendHtmlConstant(//from w w w . j a v a 2 s. c om "<div id=\"" + SafeHtmlUtils.htmlEscape(id) + "\" class=\"" + style.node() + "\">"); sb.appendHtmlConstant("<div class=\"" + style.element() + "\">"); } if (renderMode == TreeViewRenderMode.ALL || renderMode == TreeViewRenderMode.BUFFER_BODY) { sb.appendHtmlConstant(getIndentMarkup(level)); Element jointElement = null; switch (joint) { case COLLAPSED: jointElement = getImage( ts.getJointCloseIcon() == null ? resources.jointCollapsedIcon() : ts.getJointCloseIcon()); break; case EXPANDED: jointElement = getImage( ts.getJointOpenIcon() == null ? resources.jointExpandedIcon() : ts.getJointOpenIcon()); break; default: // empty } if (jointElement != null) { jointElement.addClassName(style.joint()); } sb.appendHtmlConstant( jointElement == null ? "<img src=\"" + GXT.getBlankImageUrl() + "\" style=\"width: 16px\" class=\"" + style.joint() + "\" />" : jointElement.getString()); // checkable if (checkable) { Element e = null; switch (checked) { case CHECKED: e = getImage(resources.checked()); break; case UNCHECKED: e = getImage(resources.unchecked()); break; case PARTIAL: e = getImage(resources.partialChecked()); break; } e.addClassName(style.check()); sb.appendHtmlConstant(e.getString()); } else { sb.appendHtmlConstant("<span class='" + style.check() + "'></span>"); } if (icon != null) { Element e = getImage(icon); e.addClassName(style.icon()); sb.appendHtmlConstant(e.getString()); } else { sb.appendHtmlConstant("<span class=\"" + style.icon() + "\"></span>"); } sb.appendHtmlConstant("<span class=\"" + style.text() + "\">" + text.asString() + "</span>"); } if (renderMode == TreeViewRenderMode.ALL || renderMode == TreeViewRenderMode.BUFFER_WRAP) { sb.appendHtmlConstant("</div>"); sb.appendHtmlConstant("</div>"); } }
From source file:com.smartgwt.mobile.client.widgets.tableview.TableView.java
License:Open Source License
private String formatCellValue(Record record, int rowNum, String fieldName) { int fieldNum = getFieldNum(fieldName); if (fieldNum >= 0) { final ListGridField[] fields = getFields(); if (fields != null && fieldNum < fields.length) { final ListGridField field = fields[fieldNum]; String value = field._formatCellValue(record.getAttributeAsObject(fieldName), record, rowNum, fieldNum, this); if (field._getEscapeHTML()) { value = SafeHtmlUtils.htmlEscape(value); }//w w w.j a va 2 s . co m return value; } } return record.getAttribute(fieldName); }
From source file:com.smartgwt.mobile.client.widgets.tableview.TableView.java
License:Open Source License
/** * Renders the records in <code>recordsToShow</code> on screen. * * @see #getShowRecordComponents()//from w w w . j ava 2 s. co m */ public void loadRecords(List<Record> recordsToShow) { destroyRecordComponents(); final boolean hadShowDeletableRecordsClassName, hadShowMoveableRecordsClassName; if (_ul != null) { hadShowDeletableRecordsClassName = ElementUtil.hasClassName(_ul, _CSS.tableViewShowDeleteDisclosuresClass()); hadShowMoveableRecordsClassName = ElementUtil.hasClassName(_ul, _CSS.tableViewShowMoveIndicatorsClass()); if (_ul.hasParentElement()) { _ul.removeFromParent(); } } else { hadShowDeletableRecordsClassName = false; hadShowMoveableRecordsClassName = false; } final Document document = Document.get(); _ul = document.createULElement(); _ul.addClassName(COMPONENT_CLASS_NAME); if (parentNavStack != null) { _ul.addClassName(_CSS.tableViewHasParentNavStackClass()); } if (hadShowDeletableRecordsClassName) { _ul.addClassName(_CSS.tableViewShowDeleteDisclosuresClass()); } if (hadShowMoveableRecordsClassName) { _ul.addClassName(_CSS.tableViewShowMoveIndicatorsClass()); } if (this.tableMode == TableMode.GROUPED) { _ul.addClassName(_CSS.groupedTableViewClass()); } if (recordsToShow == null) recordsToShow = Collections.emptyList(); for (int i = 0; i < recordsToShow.size(); ++i) { final Record record = recordsToShow.get(i); if (record == null) throw new NullPointerException("The Record at index " + i + " is null."); record.setAttribute(recordIndexProperty, Integer.valueOf(i)); } ListGridField groupByField = null; GroupNode[] sortedGroupNodes = null; // Handle table grouping if (groupByFieldName != null) { final ListGridField[] fields = getFields(); if (fields != null) { for (ListGridField field : fields) { if (field != null && groupByFieldName.equals(field.getName())) { groupByField = field; break; } } } if (groupByField == null) { SC.logWarn("Could not find groupByField '" + groupByFieldName + "'"); } else if (groupByField.getGroupValueFunction() == null) { SC.logWarn("The groupByField '" + groupByFieldName + "' does not have a GroupByFunction."); } else { final GroupValueFunction groupByFunction = groupByField.getGroupValueFunction(); final Map<Object, GroupNode> groupNodes = new LinkedHashMap<Object, GroupNode>(); for (Record record : recordsToShow) { final Object groupValue = groupByFunction.getGroupValue( record.getAttributeAsObject(groupByFieldName), record, groupByField, groupByFieldName, this); GroupNode groupNode = groupNodes.get(groupValue); if (groupNode == null) { groupNode = new GroupNode(groupValue); groupNodes.put(groupValue, groupNode); } groupNode._add(record); } sortedGroupNodes = groupNodes.values().toArray(new GroupNode[groupNodes.size()]); Arrays.sort(sortedGroupNodes, GroupNode._COMPARATOR); } } elementMap = new HashMap<Object, Element>(); if (getShowRecordComponents()) recordComponents = new ArrayList<Canvas>(); if (recordsToShow.isEmpty()) { if (_getData() instanceof ResultSet && !((ResultSet) _getData()).lengthIsKnown()) { _ul.setInnerText(this.getLoadingMessage()); } else { if (emptyMessage != null) _ul.setInnerText(emptyMessage); } getElement().appendChild(_ul); } else { UListElement ul = _ul; LIElement lastLI; if (sortedGroupNodes == null) { lastLI = showGroup(recordsToShow, ul); } else { assert groupByField != null; assert sortedGroupNodes.length >= 1; final GroupTitleRenderer groupTitleRenderer = groupByField.getGroupTitleRenderer(); int i = 0; LIElement li; do { final GroupNode groupNode = sortedGroupNodes[i]; groupNode._setGroupTitle( groupTitleRenderer == null ? SafeHtmlUtils.htmlEscape(groupNode._getGroupValueString()) : groupTitleRenderer.getGroupTitle(groupNode.getGroupValue(), groupNode, groupByField, groupByFieldName, this)); li = document.createLIElement(); li.setAttribute(GROUP_VALUE_STRING_ATTRIBUTE_NAME, groupNode._getGroupValueString()); if (ul == null || _ul.equals(ul)) li.addClassName(_CSS.firstTableViewGroupClass()); final String groupTitle = groupNode.getGroupTitle(); if (groupTitle == null) { li.addClassName(_CSS.tableViewGroupWithoutGroupTitleClass()); } else { final DivElement labelDiv = document.createDivElement(); labelDiv.setClassName(Label.COMPONENT_CLASS_NAME); labelDiv.setInnerHTML(groupTitle); li.appendChild(labelDiv); } ul = document.createULElement(); ul.setClassName(COMPONENT_CLASS_NAME); ul.addClassName(TABLE_GROUP_CLASS_NAME); lastLI = showGroup(groupNode._getGroupMembersList(), ul); if (i != sortedGroupNodes.length - 1 && lastLI != null) { lastLI.addClassName(_CSS.lastTableViewRowClass()); } li.appendChild(ul); _ul.appendChild(li); } while (++i < sortedGroupNodes.length); assert li != null; li.addClassName(_CSS.lastTableViewGroupClass()); } if (_getData() instanceof ResultSet) { ResultSet rs = (ResultSet) _getData(); if (rs.getFetchMode() == FetchMode.PAGED && !rs.allRowsCached()) { LIElement li = document.createLIElement(); li.setClassName(ROW_CLASS_NAME); com.google.gwt.user.client.Element loadMoreRecordsElement = (com.google.gwt.user.client.Element) li .cast(); DOM.setEventListener(loadMoreRecordsElement, this); SpanElement span = document.createSpanElement(); span.addClassName(RECORD_TITLE_CLASS_NAME); span.setInnerText(SmartGwtMessages.INSTANCE.listGrid_loadMoreRecords()); span.setAttribute(IS_LOAD_MORE_RECORDS_ATTRIBUTE_NAME, "true"); li.setAttribute(IS_LOAD_MORE_RECORDS_ATTRIBUTE_NAME, "true"); li.appendChild(span); ul.appendChild(li); lastLI = li; } } if (lastLI != null) { lastLI.addClassName(_CSS.lastTableViewRowClass()); } getElement().appendChild(_ul); setSelecteds(); } if (isAttached()) { _fireContentChangedEvent(); // If this `TableView' is not currently attached, defer the firing of the content // changed event. } else { fireContentChangedOnLoad = true; } }
From source file:com.tasktop.c2c.server.profile.web.ui.client.view.components.ProjectInvitationView.java
License:Open Source License
private void updateUi() { projectInvitation.setText(profileMessages.projectInvited(project.getName())); if (project.getDescription() != null) { projectDescription.setInnerText(SafeHtmlUtils.htmlEscape(project.getDescription())); }//w ww .j a v a 2 s .co m }
From source file:com.tmc.client.ui.field.LookupFieldAppearance.java
License:sencha.com license
protected void renderInput(SafeHtmlBuilder shb, String value, SafeStyles inputStyles, FieldAppearanceOptions options) { StringBuilder sb = new StringBuilder(); sb.append("<input "); if (options.isDisabled()) { sb.append("disabled=true "); }/*from www . ja v a 2 s . c o m*/ if (options.getName() != null) { 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 ("".equals(value) && 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); sb.append("type='text' value='").append(SafeHtmlUtils.htmlEscape(value)).append("' "); sb.append("/>"); shb.append(SafeHtmlUtils.fromTrustedString(sb.toString())); }
From source file:com.tractionsoftware.gwt.demo.history.client.HistoryDemo.java
License:Apache License
@Override public void onModuleLoad() { RootPanel.get("location").add(location); RootPanel.get("links").add(links); RootPanel.get("events").add(events); History.addValueChangeHandler(new ValueChangeHandler<String>() { @Override/* w w w . j av a 2s . co m*/ public void onValueChange(ValueChangeEvent<String> event) { showLocationData(event.getValue()); events.insertItem("[" + new Date() + "] ValueChangeEvent: value=" + event.getValue(), 0); } }); showLocationData(""); String hash = "#" + token; String uri = Document.get().getBody().getAttribute("data-file") + hash; links.setText(0, 0, "GWT Hyperlink"); links.setWidget(0, 1, new Hyperlink(SafeHtmlUtils.fromString(token), token)); links.setText(1, 0, "HTML Hash"); links.setHTML(1, 1, "<a href=\"" + SafeHtmlUtils.htmlEscape(hash) + "\">" + SafeHtmlUtils.htmlEscape(hash) + "</a>"); links.setText(2, 0, "GWT Anchor"); links.setWidget(2, 1, new Anchor(SafeHtmlUtils.fromString(uri), uri)); links.setText(3, 0, "HTML Relative URI"); links.setHTML(3, 1, "<a href=\"" + SafeHtmlUtils.htmlEscape(uri) + "\">" + SafeHtmlUtils.htmlEscape(uri) + "</a>"); events.setVisibleItemCount(20); events.setWidth("800px"); }