Example usage for com.google.gwt.safehtml.shared SafeHtmlBuilder toSafeHtml

List of usage examples for com.google.gwt.safehtml.shared SafeHtmlBuilder toSafeHtml

Introduction

In this page you can find the example usage for com.google.gwt.safehtml.shared SafeHtmlBuilder toSafeHtml.

Prototype

public SafeHtml toSafeHtml() 

Source Link

Document

Returns the safe HTML accumulated in the builder as a SafeHtml .

Usage

From source file:com.tasktop.c2c.server.tasks.client.widgets.TasksSummaryView.java

License:Open Source License

public void createTaskSegment(String segmentTitle, List<Task> segmentTaskList) {

    // This was originally implemented using a similar pattern to ApplicationCard - however, that way took several
    // seconds on large lists and this is basically instantaneous (even though it doesn't look as pretty).

    SafeHtmlBuilder bodyBuilder = new SafeHtmlBuilder();

    int numClosed = 0;

    for (Task curTask : segmentTaskList) {

        bodyBuilder.appendHtmlConstant("<div class=\"task-summary-card\">");

        Anchor link = new Anchor(tasksMessages.taskWithId(curTask.getId()));
        link.setHref(ProjectTaskPlace.createPlace(appId, curTask.getId()).getHref());

        if (!curTask.getStatus().isOpen()) {
            link.addStyleName("resolved");
            numClosed++;/*from   ww w  . j  a  v  a  2  s  .c om*/
        }

        bodyBuilder.appendHtmlConstant(link.toString());
        bodyBuilder.appendHtmlConstant(" -- ");
        bodyBuilder.appendEscaped(curTask.getShortDescription());
        bodyBuilder.appendHtmlConstant("<div class=\"clearleft\"></div></div>");

    }

    SafeHtmlBuilder headerBuilder = new SafeHtmlBuilder();

    if (segmentTitle != null) {
        int total = segmentTaskList.size();
        int numOpen = total - numClosed;
        Task sampleTask = segmentTaskList.get(0);

        Anchor link = new Anchor(segmentTitle,
                ProjectTasksSummaryPlace
                        .createPlaceForComponentAndRelease(appId, (Integer) productId,
                                sampleTask.getComponent().getId(), sampleTask.getMilestone().getValue())
                        .getHref());

        // We have a title, so insert it at the beginning of the HTML.
        headerBuilder.appendHtmlConstant("<h3 class=\"task-summary-header\">");
        headerBuilder
                .appendEscaped(tasksMessages.taskSummaryHeader(link.toString(), total, numOpen, numClosed));
        headerBuilder.appendHtmlConstant("</h3>");
    }

    // Now, add in the body after the header.
    headerBuilder.append(bodyBuilder.toSafeHtml());

    taskSummaryPanel.add(new HTML(headerBuilder.toSafeHtml()));
}

From source file:com.tasktop.c2c.server.tasks.client.widgets.TaskViewImpl.java

License:Open Source License

private SafeHtml getHtmlForStrings(List<String> strings) {
    SafeHtmlBuilder shb = new SafeHtmlBuilder();

    for (int i = 0; i < strings.size(); i++) {
        // First, append this string as an escaped value to prevent XSS
        shb.appendEscaped(strings.get(i));

        // Then, if this isn't the last tag, append a <br/>
        if (i < (strings.size() - 1)) {
            shb.appendHtmlConstant("<br/>");
        }/* w  ww .j av a 2 s  . co m*/
    }

    // Check if we ended up with a blank string - if we did, send back a default
    if (strings.size() == 0) {
        shb.appendEscaped(commonProfileMessages.none());
    }

    return shb.toSafeHtml();
}

From source file:com.ui.gwt.mobile.client.components.ContactListPanel.java

License:Apache License

private void render() {
    PerfTimer timer = PerfTimer.get(this, "render");
    SafeHtmlBuilder builder = new SafeHtmlBuilder();
    if (data != null) {
        for (Contact c : data) {
            builder.append(TEMPLATE.item("", AppResources.INSTANCE.css().profilePic(), c.getPicURL(),
                    AppResources.INSTANCE.css().detailBlock(), c.getName(), c.getEmail(), c.getPhone()));
        }//from w w w .  j  a va2  s  .  c o m
    } else {
        builder.append(TEMPLATE.loading(AppResources.INSTANCE.css().loading(),
                AppResources.INSTANCE.loadingImage().getURL(), Messages.INSTANCE.listLoading()));
    }
    getElement().setInnerHTML(builder.toSafeHtml().asString());
    timer.end();
}

From source file:com.ui.gwt.mobile.client.components.DetailPanel.java

License:Apache License

public void setData(Contact data) {
    SafeHtmlBuilder builder = new SafeHtmlBuilder();
    builder.append(TEMPLATE.activeItem("tel:" + data.getPhone(), data.getPhone()));
    builder.append(TEMPLATE.activeItem("mailto:" + data.getEmail(), data.getEmail()));
    builder.append(TEMPLATE.activeItem(data.getWebAddr(), data.getWebAddr()));
    builder.append(TEMPLATE.spacer());/*w w w  . j  a v  a 2  s.c  o m*/
    builder.append(TEMPLATE.item(data.getAddr1()));
    builder.append(TEMPLATE.item(data.getAddr2()));
    String template = TEMPLATE.detail(AppResources.INSTANCE.css().details(), "",
            AppResources.INSTANCE.css().profilePic(), data.getPicURL(),
            AppResources.INSTANCE.css().detailBlock(), data.getName(), builder.toSafeHtml()).asString();

    detail.setInnerHTML(template);
    //        buildMap(data);
}

From source file:com.watopi.chosen.client.ChosenImpl.java

License:Open Source License

private void resultsBuild() {

    selectItems = new SelectParser().parse(selectElement);

    if (isMultiple && choices > 0) {
        searchChoices.find("li." + css.searchChoice()).remove();
        choices = 0;//  www  .j  a  va 2  s.  c  o m
    } else if (!isMultiple) {
        selectedItem.addClass(css.chznDefault()).find("span").text(defaultText);

        if (selectElement.getOptions().getLength() <= options.getDisableSearchThreshold()) {
            container.addClass(css.chznContainerSingleNoSearch());
        } else {
            container.removeClass(css.chznContainerSingleNoSearch());
        }
    }

    SafeHtmlBuilder content = new SafeHtmlBuilder();

    for (int i = 0; i < selectItems.length(); i++) {
        SelectItem item = selectItems.get(i);

        if (item.isGroup()) {
            SafeHtml result = resultAddGroup((GroupItem) item);
            if (result != null) {
                content.append(result);
            }
        } else {
            OptionItem optionItem = (OptionItem) item;

            if (optionItem.isEmpty()) {
                continue;
            }

            SafeHtml optionHtml = resultAddOption(optionItem);
            if (optionHtml != null) {
                content.append(optionHtml);
            }

            if (optionItem.isSelected() && isMultiple) {
                choiceBuild(optionItem);
            } else if (optionItem.isSelected() && !isMultiple) {
                selectedItem.removeClass(css.chznDefault()).find("span").text(optionItem.getText());
                if (allowSingleDeselect) {
                    singleDeselectControlBuild();
                }
            }
        }
    }
    searchFieldDisabled();
    showSearchFieldDefault();
    searchFieldScale();

    searchResults.html(content.toSafeHtml().asString());

}

From source file:cz.metacentrum.perun.webgui.widgets.UnaccentMultiWordSuggestOracle.java

License:Apache License

/**
 * Returns real suggestions with the given query in <code>strong</code> html
 * font./* w  w  w .  j  a v a 2  s  .  c o  m*/
 *
 * @param query query string
 * @param candidates candidates
 * @return real suggestions
 */
private List<MultiWordSuggestion> convertToFormattedSuggestions(String query, List<String> candidates) {
    List<MultiWordSuggestion> suggestions = new ArrayList<MultiWordSuggestion>();

    for (int i = 0; i < candidates.size(); i++) {
        String candidate = candidates.get(i);
        int cursor = 0;
        int index = 0;
        // Use real suggestion for assembly.
        String formattedSuggestion = toRealSuggestions.get(candidate);

        // Create strong search string.
        SafeHtmlBuilder accum = new SafeHtmlBuilder();

        String[] searchWords = query.split(WHITESPACE_STRING);
        while (true) {
            WordBounds wordBounds = findNextWord(candidate, searchWords, index);
            if (wordBounds == null) {
                break;
            }
            if (wordBounds.startIndex == 0 || WHITESPACE_CHAR == candidate.charAt(wordBounds.startIndex - 1)) {
                String part1 = formattedSuggestion.substring(cursor, wordBounds.startIndex);
                String part2 = formattedSuggestion.substring(wordBounds.startIndex, wordBounds.endIndex);
                cursor = wordBounds.endIndex;
                accum.appendEscaped(part1);
                accum.appendHtmlConstant("<strong>");
                accum.appendEscaped(part2);
                accum.appendHtmlConstant("</strong>");
            }
            index = wordBounds.endIndex;
        }

        // Check to make sure the search was found in the string.
        if (cursor == 0) {
            continue;
        }

        accum.appendEscaped(formattedSuggestion.substring(cursor));
        MultiWordSuggestion suggestion = createSuggestion(formattedSuggestion, accum.toSafeHtml().asString());
        suggestions.add(suggestion);
    }
    return suggestions;
}

From source file:de.eckhartarnold.client.Caption.java

License:Apache License

/**
 * Returns the current Text the caption displays.
 * //from  w  w w .  j a  v a  2 s .  c  o m
 * @return the HTML formatted Text of the caption
 */
public SafeHtml getText() {
    if (current == -1)
        return (spacing == NO_SPACING) ? emptySpacer : spacer;
    else {
        SafeHtmlBuilder builder = new SafeHtmlBuilder();
        if (spacing == BOTTOM_SPACING) {
            builder.append(stuffings[current]);
            builder.append(captions[current]);
            return builder.toSafeHtml();
        } else if (spacing == TOP_SPACING) {
            builder.append(captions[current]);
            builder.append(stuffings[current]);
            return builder.toSafeHtml();
        } else {
            return captions[current];
        }
    }
}

From source file:de.knightsoftnet.navigation.client.ui.navigation.AbstractNavigationStructure.java

License:Apache License

protected SafeHtml createMenuEntry(final ImageResource pimage, final String ptext) {
    final SafeHtmlBuilder menuShb = new SafeHtmlBuilder();
    menuShb.append(AbstractImagePrototype.create(pimage).getSafeHtml()).append(' ').appendEscaped(ptext);
    return menuShb.toSafeHtml();
}

From source file:de.knightsoftnet.validators.client.decorators.AbstractDecorator.java

License:Apache License

/**
 * The default implementation will display, but not consume, received errors whose
 * {@link EditorError#getEditor() getEditor()} method returns the Editor passed into
 * {@link #setEditor}./* w w  w . j ava2s  .  c o  m*/
 *
 * @param errors a List of {@link EditorError} instances
 */
@Override
public void showErrors(final List<EditorError> errors) {
    final Set<String> messages = new HashSet<String>();
    for (final EditorError error : errors) {
        if (this.editorErrorMatches(error)) {
            messages.add(error.getMessage());
        }
    }
    if (messages.isEmpty()) {
        this.errorLabel.setText(StringUtils.EMPTY);
        this.errorLabel.getElement().getStyle().setDisplay(Display.NONE);
        if (this.contents.getWidget() != null) {
            this.contents.getWidget().removeStyleName(this.decoratorStyle.errorInputStyle());
            this.contents.getWidget().addStyleName(this.decoratorStyle.validInputStyle());
        }
    } else {
        if (this.contents.getWidget() != null) {
            this.contents.getWidget().removeStyleName(this.decoratorStyle.validInputStyle());
            this.contents.getWidget().addStyleName(this.decoratorStyle.errorInputStyle());
            if (this.focusOnError) {
                this.setFocus(true);
            }
        }
        final SafeHtmlBuilder sb = new SafeHtmlBuilder();
        for (final String message : messages) {
            sb.appendEscaped(message);
            sb.appendHtmlConstant("<br />");
        }
        this.errorLabel.setHTML(sb.toSafeHtml());
        this.errorLabel.getElement().getStyle().setDisplay(Display.TABLE);
    }
}

From source file:de.uni_koeln.spinfo.maalr.webapp.ui.editor.client.entry.list.column.LemmaVersionColumnHighlightable.java

License:Apache License

@Override
public SafeHtml getValue(LemmaVersion object) {
    SafeHtmlBuilder sb = new SafeHtmlBuilder();
    LemmaDescription description = AsyncLemmaDescriptionLoader.getDescription();
    String toDisplay = description.toString(object, UseCase.RESULT_LIST, true) + "  "
            + description.toString(object, UseCase.RESULT_LIST, false);
    if (query != null && query.isHighlight()) {
        toDisplay = Highlighter.highlight(toDisplay, query.getValue("searchPhrase"));
    }// w  w w.j  a  v a 2 s.c  om
    sb.appendHtmlConstant(toDisplay);
    return sb.toSafeHtml();
}