List of usage examples for com.google.gwt.safehtml.shared SafeHtmlUtils htmlEscape
public static String htmlEscape(String s)
From source file:com.unilorraine.projetdevie.client.ui.viewmodules.preparationmodule.PreparationModuleActivity.java
License:Open Source License
/** * Initialize the menu// w w w .j a v a2 s. c o m */ private void intiMenu() { removeAll(); //Item 1 sub-tree TreeItem item1 = new TreeItem(); item1.setText(SafeHtmlUtils.htmlEscape(CATEGORY_MENU)); item1.setUserObject(CATEGORY_MENU); addItem(item1); }
From source file:com.vaadin.client.connectors.grid.TreeRendererConnector.java
License:Apache License
@Override public Renderer<String> createRenderer() { return new HtmlRenderer() { @Override/*www . j a v a2 s .c o m*/ public void render(RendererCellReference cell, String htmlString) { String content = "<span class=\"v-captiontext\">" + getContentString(htmlString) + "</span>"; JsonObject row = getParent().getParent().getDataSource().getRow(cell.getRowIndex()); if (row != null && row.hasKey("itemIcon")) { String resourceId = row.getString("itemIcon"); Element element = getConnection().getIcon(getResourceUrl(resourceId)).getElement(); content = element.getString() + content; } super.render(cell, content); } private String getContentString(String htmlString) { switch (getState().mode) { case HTML: return htmlString; case PREFORMATTED: return "<pre>" + SafeHtmlUtils.htmlEscape(htmlString) + "</pre>"; default: return SafeHtmlUtils.htmlEscape(htmlString); } } }; }
From source file:com.vaadin.client.connectors.tree.TreeRendererConnector.java
License:Apache License
@Override public Renderer<String> createRenderer() { return new HtmlRenderer() { @Override// ww w . j a v a 2 s .c o m public void render(RendererCellReference cell, String htmlString) { String content = SafeHtmlUtils.htmlEscape(htmlString); JsonObject row = getParent().getParent().getDataSource().getRow(cell.getRowIndex()); if (row != null && row.hasKey("itemIcon")) { String resourceId = row.getString("itemIcon"); Element element = getConnection().getIcon(getResourceUrl(resourceId)).getElement(); content = element.getString() + " " + content; } super.render(cell, content); } }; }
From source file:com.watopi.chosen.client.ChosenImpl.java
License:Open Source License
private void winnowResults() { noResultClear();/* w w w .jav a2s. c o m*/ int results = 0; String searchText = defaultText.equals(searchField.val()) ? "" : searchField.val().trim(); searchText = SafeHtmlUtils.htmlEscape(searchText); String regexAnchor = options.isSearchContains() ? "" : "^"; // escape reg exp special chars String escapedSearchText = regExpChars.replace(searchText, "\\$&"); String test2 = "test"; test2.substring(1); RegExp regex = RegExp.compile(regexAnchor + escapedSearchText, "i"); RegExp zregex = RegExp.compile("(" + escapedSearchText + ")", "i"); for (int i = 0; i < selectItems.length(); i++) { SelectItem item = selectItems.get(i); if (item.isDisabled() || item.isEmpty()) { continue; } if (item.isGroup()) { $('#' + item.getDomId()).css("display", "none"); } else { OptionItem option = (OptionItem) item; if (!(isMultiple && option.isSelected())) { boolean found = false; String resultId = option.getDomId(); GQuery result = $("#" + resultId); String optionContent = option.getHtml(); if (regex.test(optionContent)) { found = true; results++; } else if (optionContent.indexOf(" ") >= 0 || optionContent.indexOf("[") == 0) { String[] parts = optionContent.replaceAll("\\[|\\]", "").split(" "); for (String part : parts) { if (regex.test(part)) { found = true; results++; } } } if (found) { String text; if (searchText.length() > 0) { text = zregex.replace(optionContent, "<em>$1</em>"); } else { text = optionContent; } result.html(text); resultActivate(result); if (option.getGroupArrayIndex() != -1) { $("#" + selectItems.get(option.getGroupArrayIndex()).getDomId()).css("display", "list-item"); } } else { if (resultHighlight != null && resultId.equals(resultHighlight.attr("id"))) { resultClearHighlight(); } resultDeactivate(result); } } } } if (results < 1 && searchText.length() > 0) { noResults(searchText); } else { winnowResultsSetHighlight(); } }
From source file:cz.cas.lib.proarc.webapp.client.ErrorHandler.java
License:Open Source License
private void handleError(TransportError te, DSResponse response, DSRequest request) { String requestDump = ClientUtils.dump(request.getJsObj()); // message from original error handler; contains URL Object smartGwtMsg = response.getDataAsString(); if (te == null || response.getTransactionNum() != te.getTransactionNum()) { String debugInfo = ClientUtils.format( "Invalid transaction numbers %s != %s" + "\n%s\nStatus: %s\nQuery: %s", response.getTransactionNum(), te == null ? null : te.getTransactionNum(), smartGwtMsg, response.getStatus(), requestDump); SC.logWarn(debugInfo);/*from www.ja v a 2s .com*/ } // boolean clientError = te.getHttpResponseCode() >= 400 && te.getHttpResponseCode() < 500; String clientMsg = getClientMessage(te, response, request); String debugInfo = ClientUtils.format("%s\nStatus: %s\nQuery: %s", smartGwtMsg, te == null ? response.getStatus() : te.getStatus(), requestDump); String htmlDebugInfo = ClientUtils.format("%s<br/>Status: %s<br/>Query: %s", smartGwtMsg, te == null ? response.getStatus() : te.getStatus(), SafeHtmlUtils.htmlEscape(requestDump)); warn(clientMsg, te == null ? response.getDataAsString() : te.getHttpResponseText(), htmlDebugInfo); SC.logWarn(debugInfo); }
From source file:cz.metacentrum.perun.webgui.widgets.UnaccentMultiWordSuggestOracle.java
License:Apache License
/** * A convenience method to set default suggestions using plain text strings. * * Note to use this method each default suggestion must be plain text. * * @param suggestionList the default list of suggestions *///from w w w . j a v a 2s . c o m public final void setDefaultSuggestionsFromText(Collection<String> suggestionList) { Collection<Suggestion> accum = new ArrayList<Suggestion>(); for (String candidate : suggestionList) { accum.add(createSuggestion(candidate, SafeHtmlUtils.htmlEscape(candidate))); } setDefaultSuggestions(accum); }
From source file:de.uni_koeln.spinfo.maalr.configuration.Environment.java
License:Apache License
public Environment() { version = "Unknown"; configuration = Configuration.getInstance(); configuration.getLemmaDescription().setDefaultEscaper(new Escaper() { @Override//from ww w . ja va2 s . c om public String escape(String text) { return SafeHtmlUtils.htmlEscape(text); } }); /* * Load application properties, which contain build and version * number */ Properties props = new Properties(); try { props.load(getClass().getClassLoader().getResourceAsStream("application.properties")); } catch (IOException e) { logger.error("Failed to read application properties!", e); } version = (String) props.get("application.version"); name = (String) props.getProperty("application.name"); appProperties = new AppProperties(); appProperties.setAppName(name); appProperties.setAppVersion(version); configuration.getLemmaDescription(); luceneConfig = new LuceneConfiguration(); luceneConfig.setBaseDirectory(configuration.getLuceneDir()); logger.info("**********************************************************************************"); logger.info("Initializing " + appProperties.getAppName() + " " + appProperties.getAppVersion()); logger.info("**********************************************************************************"); }
From source file:de.uni_koeln.spinfo.maalr.webapp.ui.common.client.AsyncLemmaDescriptionLoader.java
License:Apache License
public static void afterLemmaDescriptionLoaded(final AsyncCallback<LemmaDescription> callback) { if (description == null) { service.getLemmaDescription(new AsyncCallback<LemmaDescription>() { @Override/*w ww .ja v a 2 s . com*/ public void onSuccess(LemmaDescription loaded) { loaded.setDefaultEscaper(new Escaper() { @Override public String escape(String text) { return SafeHtmlUtils.htmlEscape(text); } }); description = loaded; callback.onSuccess(description); } @Override public void onFailure(Throwable arg0) { Dialog.showError("Service unavailable", arg0); } }); } else { // command.execute(); callback.onSuccess(description); } }
From source file:edu.arizona.biosemantics.gxt.theme.green.client.base.button.Css3ButtonCellAppearance.java
License:sencha.com license
@Override public void render(ButtonCell<M> cell, Context context, M 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? String text = hasConstantHtml ? cell.getText() : (value != null && !isBoolean) ? SafeHtmlUtils.htmlEscape(value.toString()) : ""; ImageResource icon = cell.getIcon(); IconAlign iconAlign = cell.getIconAlign(); String arrowClass = ""; String scaleClass = ""; String iconClass = ""; int width = cell.getWidth(); int height = cell.getHeight(); boolean hasIcon = cell.getIcon() != null; boolean isSplitButton = cell instanceof SplitButtonCell; boolean hasMenu = cell.getMenu() != null; boolean hasWidth = width != -1; if (cell.getMenu() != null) { if (cell instanceof SplitButtonCell) { switch (cell.getArrowAlign()) { case RIGHT: arrowClass = style.split(); break; case BOTTOM: arrowClass = style.splitBottom(); break; }/* w w w . jav a2 s .co m*/ } else { switch (cell.getArrowAlign()) { case RIGHT: arrowClass = style.arrow(); break; case BOTTOM: arrowClass = style.arrowBottom(); break; } } } ButtonScale scale = cell.getScale(); switch (scale) { case SMALL: scaleClass = style.small(); break; case MEDIUM: scaleClass = style.medium(); break; case LARGE: scaleClass = style.large(); break; } if (icon != null) { switch (iconAlign) { case TOP: iconClass = style.iconTop(); break; case BOTTOM: iconClass = style.iconBottom(); break; case LEFT: iconClass = style.iconLeft(); break; case RIGHT: iconClass = style.iconRight(); break; } } String buttonClass = style.button(); boolean hasText = text != null && !text.equals(""); if (!hasText) { buttonClass += " " + style.noText(); } // toggle button if (value == Boolean.TRUE) { buttonClass += " " + style.pressed(); } String innerClass = style.buttonInner() + " " + iconClass; innerClass += " " + arrowClass; innerClass += " " + scaleClass; SafeHtmlBuilder builder = new SafeHtmlBuilder(); SafeStylesBuilder ss = new SafeStylesBuilder(); if (height != -1) { ButtonDetails bd = resources.theme().button(); EdgeDetails padding = bd.padding(); EdgeDetails paddingInner = bd.radiusMinusBorderWidth(); int ah = height; ah -= padding.top(); ah -= padding.bottom(); ah -= paddingInner.top(); ah -= paddingInner.bottom(); ss.appendTrustedString("line-height: " + ah + "px;"); } builder.appendHtmlConstant("<div class='" + buttonClass + "'>"); // get iconbuilder ready SafeHtmlBuilder iconBuilder = new SafeHtmlBuilder(); if (icon != null) { int iconWidth = icon != null ? icon.getWidth() : 0; int iconHeight = icon != null ? icon.getHeight() : 0; String styles = "width: " + iconWidth + "px; height: " + iconHeight + "px;"; iconBuilder.appendHtmlConstant("<div class='" + iconClass + "' style='" + styles + "'>"); iconBuilder.append(AbstractImagePrototype.create(icon).getSafeHtml()); iconBuilder.appendHtmlConstant("</div>"); } // for left / right aligned icons with a fixed button width we render the icon outside of the inner div if (hasWidth && hasIcon && iconAlign == IconAlign.LEFT) { builder.append(iconBuilder.toSafeHtml()); } if (hasWidth && hasIcon && (iconAlign == IconAlign.LEFT)) { int tw = width - (resources.theme().button().borderRadius() * 2); if (isSplitButton && cell.getArrowAlign() == ButtonArrowAlign.RIGHT) { tw -= resources.split().getWidth() + 10; } if (!isSplitButton && iconAlign == IconAlign.LEFT && hasMenu && cell.getArrowAlign() == ButtonArrowAlign.RIGHT) { tw -= resources.arrow().getWidth() + 10; } if (hasIcon && iconAlign == IconAlign.LEFT) { tw -= icon.getWidth(); } ss.appendTrustedString("width: " + tw + "px;"); } builder.appendHtmlConstant("<div class='" + innerClass + "' style='" + ss.toSafeStyles().asString() + "'>"); if (icon != null) { if ((!hasWidth && iconAlign == IconAlign.LEFT) || iconAlign == IconAlign.TOP) { builder.append(iconBuilder.toSafeHtml()); } builder.appendHtmlConstant(text); if (iconAlign == IconAlign.RIGHT || iconAlign == IconAlign.BOTTOM) { builder.append(iconBuilder.toSafeHtml()); } } else { builder.appendHtmlConstant(text); } builder.appendHtmlConstant("</div></div>"); sb.append(builder.toSafeHtml()); }
From source file:edu.arizona.biosemantics.gxt.theme.green.client.base.field.Css3TextAreaAppearance.java
License:sencha.com license
@Override public void render(SafeHtmlBuilder sb, String value, FieldAppearanceOptions options) { String inputStyles = ""; String wrapStyles = ""; int width = options.getWidth(); int height = options.getHeight(); 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(); }//from w w w .ja v a2 s .c om empty = true; } 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(); } String ro = options.isReadonly() ? " readonly" : ""; 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>"); }