Example usage for com.google.gwt.safehtml.shared SafeHtmlUtils htmlEscape

List of usage examples for com.google.gwt.safehtml.shared SafeHtmlUtils htmlEscape

Introduction

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

Prototype

public static String htmlEscape(String s) 

Source Link

Document

HTML-escapes a string.

Usage

From source file:net.scran24.user.shared.Meal.java

License:Apache License

public String safeName() {
    return SafeHtmlUtils.htmlEscape(name.toLowerCase());
}

From source file:org.activityinfo.ui.client.page.config.AddLockedPeriodDialog.java

License:Open Source License

private void initializeComponent() {
    setWidth(400);//from w  w  w. j  a  va 2  s .c  o  m
    setHeight(280);

    setHeaderVisible(false);

    fieldsetContainer = new FieldSet();
    fieldsetContainer.setHeadingHtml(SafeHtmlUtils.htmlEscape(I18N.CONSTANTS.type()));

    comboboxProjects = new ComboBox<ProjectDTO>();
    storeProjects = new ListStore<ProjectDTO>();
    comboboxProjects.setStore(storeProjects);
    comboboxProjects.setDisplayField("name");
    comboboxProjects.setForceSelection(true);
    comboboxProjects.setTriggerAction(TriggerAction.ALL);
    comboboxProjects.setEditable(false);

    comboboxActivities = new ComboBox<ActivityDTO>();
    storeActivities = new ListStore<ActivityDTO>();
    comboboxActivities.setStore(storeActivities);
    comboboxActivities.setDisplayField("name");
    comboboxActivities.setForceSelection(true);
    comboboxActivities.setTriggerAction(TriggerAction.ALL);
    comboboxActivities.setEditable(false);

    radiogroupContainer = new RadioGroup();
    radiogroupContainer.setFieldLabel(I18N.CONSTANTS.type());

    labelDatabase = new LabelField(I18N.CONSTANTS.database());
    labelDatabase.setWidth(100);
    labelDatabase.setUseHtml(false);

    labelDatabaseName = new LabelField();
    labelDatabaseName.setUseHtml(false);

    radioDatabase = new Radio();
    radioDatabase.setFieldLabel(I18N.CONSTANTS.database());
    radiogroupContainer.add(radioDatabase);

    panelDatabase = new HorizontalPanel();
    panelDatabase.add(labelDatabase);
    panelDatabase.add(radioDatabase);
    panelDatabase.add(labelDatabaseName);
    fieldsetContainer.add(panelDatabase);

    radioActivity = new Radio();
    radioActivity.setFieldLabel(I18N.CONSTANTS.activity());

    labelActivity = new LabelField(I18N.CONSTANTS.activity());
    labelActivity.setWidth(100);
    labelActivity.setUseHtml(false);

    panelActivity = new HorizontalPanel();
    panelActivity.add(labelActivity);
    panelActivity.add(radioActivity);
    panelActivity.add(comboboxActivities);
    fieldsetContainer.add(panelActivity);
    radiogroupContainer.add(radioActivity);

    radioProject = new Radio();
    radioProject.setFieldLabel(I18N.CONSTANTS.project());
    radioProject.addListener(Events.Change, new Listener<FieldEvent>() {
        @Override
        public void handleEvent(FieldEvent be) {
            comboboxProjects.setEnabled(radioProject.getValue());
        }
    });

    labelProject = new LabelField(I18N.CONSTANTS.project());
    labelProject.setWidth(100);
    labelProject.setUseHtml(false);

    panelProject = new HorizontalPanel();
    panelProject.add(labelProject);
    panelProject.add(radioProject);
    panelProject.add(comboboxProjects);
    fieldsetContainer.add(panelProject);
    radiogroupContainer.add(radioProject);

    add(fieldsetContainer);

    textfieldName = new TextField<String>();
    textfieldName.setFieldLabel(I18N.CONSTANTS.name());
    textfieldName.setAllowBlank(false);
    add(textfieldName);

    checkboxEnabled = new CheckBox();
    checkboxEnabled.setFieldLabel(I18N.CONSTANTS.enabledColumn());
    add(checkboxEnabled);

    datefieldToDate = new DateField();

    datefieldFromDate = new DateField();
    datefieldFromDate.setFieldLabel(I18N.CONSTANTS.fromDate());
    datefieldFromDate.setAllowBlank(false);
    datefieldFromDate.setValidator(new Validator() {
        @Override
        public String validate(Field<?> field, String value) {
            if (datefieldFromDate.getValue().after(datefieldToDate.getValue())) {
                return I18N.CONSTANTS.fromDateIsBeforeToDate();
            }
            return null;
        }
    });
    add(datefieldFromDate);

    datefieldToDate.setFieldLabel(I18N.CONSTANTS.toDate());
    datefieldToDate.setAllowBlank(false);
    add(datefieldToDate);

    radiogroupContainer.addListener(Events.Change, new Listener<FieldEvent>() {

        @Override
        public void handleEvent(FieldEvent be) {
            comboboxActivities.setAllowBlank(!radioActivity.getValue());
            comboboxProjects.setAllowBlank(!radioProject.getValue());
            comboboxActivities.clearInvalid();
            comboboxProjects.clearInvalid();
        }
    });
}

From source file:org.activityinfo.ui.client.page.report.editor.ElementWidget.java

License:Open Source License

private void renderStaticHtml() {
    String text = ((TextReportElement) model).getText();
    updateHtml(text != null ? SafeHtmlUtils.htmlEscape(text) : "");
}

From source file:org.activityinfo.ui.client.page.report.editor.ElementWidget.java

License:Open Source License

private void editTitle() {
    final MessageBox box = new MessageBox();
    box.setTitleHtml(SafeHtmlUtils.htmlEscape(I18N.CONSTANTS.changeTitleDialogTitle()));
    box.setType(MessageBoxType.PROMPT);/*from   w  w  w.  j a  va  2 s. c  o  m*/
    box.setButtons(Dialog.OKCANCEL);
    box.show();
    box.getTextBox().setValue(model.getTitle());
    box.addCallback(new Listener<MessageBoxEvent>() {

        @Override
        public void handleEvent(MessageBoxEvent be) {
            if (be.getButtonClicked().getItemId().equals(Dialog.OK)) {
                model.setTitle(box.getTextBox().getValue());
                titleElement.setInnerText(ElementTitles.format(model));
            }
        }
    });
}

From source file:org.appverse.web.framework.frontend.gwt.theme.bluetouch.client.button.AppverseWebButtonCellDefaultAppearance.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?
    String text = 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. java 2  s . co 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;
            }

        } 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;
    }

    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(text);
            length += 6; // frames

            if (icon != null) {
                switch (iconAlign) {
                case LEFT:
                case RIGHT:
                    length += icon.getWidth();
                    break;
                }
            }

            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;
    if (GXT.isIE6() || GXT.isIE7()) {
        arrowCls += " " + CommonStyles.get().inlineBlock();
    }

    inside.appendHtmlConstant("<div class='" + innerWrap + "'>");
    inside.appendHtmlConstant("<table cellpadding=0 cellspacing=0 class='" + style.mainTable() + "'>");

    if (icon != null) {
        switch (iconAlign) {
        case LEFT:
            inside.appendHtmlConstant("<tr>");
            writeIcon(inside, icon, height);
            if (text != null) {
                int w = width - (icon != null ? icon.getWidth() : 0) - 4;
                writeText(inside, text, w, height);
            }
            inside.appendHtmlConstant("</tr>");
            break;
        case RIGHT:
            inside.appendHtmlConstant("<tr>");
            if (text != null) {
                int w = width - (icon != null ? icon.getWidth() : 0) - 4;
                writeText(inside, text, w, height);
            }
            writeIcon(inside, icon, height);
            inside.appendHtmlConstant("</tr>");
            break;
        case TOP:
            inside.appendHtmlConstant("<tr>");
            writeIcon(inside, icon, height);
            inside.appendHtmlConstant("</tr>");
            if (text != null) {
                inside.appendHtmlConstant("<tr>");
                writeText(inside, text, width, height);
                inside.appendHtmlConstant("</tr>");
            }
            break;
        case BOTTOM:
            if (text != null) {
                inside.appendHtmlConstant("<tr>");
                writeText(inside, text, width, height);
                inside.appendHtmlConstant("</tr>");
            }
            inside.appendHtmlConstant("<tr>");
            writeIcon(inside, icon, height);
            inside.appendHtmlConstant("</tr>");
            break;
        }

    } else {
        inside.appendHtmlConstant("<tr>");
        if (text != null) {
            writeText(inside, text, 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:org.appverse.web.framework.frontend.gwt.theme.bluetouch.client.field.AppverseWebTextFieldAppearance.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" : "";

    boolean empty = false;

    if ((value == null || value.equals("")) && options.getEmptyText() != null) {
        value = options.getEmptyText();/*from w  ww.ja  va  2 s  .  com*/
        empty = true;
    }

    if (width != -1) {
        wrapStyles += "width:" + width + "px;";
        // 6px margin, 2px border
        width -= 8;
        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 + ">");

}

From source file:org.appverse.web.framework.frontend.gwt.theme.bluetouch.client.field.AppverseWebTriggerFieldAppearance.java

License:sencha.com license

/**
 * Helper method to render the input in the trigger field. 
 *///from w w  w .  j  a  v  a  2 s  .co m
private 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(style.field()).append(" ").append(style.text());

    if (value.equals("") && options.getEmptyText() != null) {
        sb.append(" ").append(style.empty());
        value = options.getEmptyText();
    }

    if (!options.isEditable()) {
        sb.append(" ").append(style.noedit());
    }
    sb.append("' ");

    //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:org.eclipse.che.ide.console.OutputConsoleViewImpl.java

License:Open Source License

@Override
public void print(final String text, boolean carriageReturn, String color) {
    if (this.carriageReturn) {
        Node lastChild = consoleLines.getElement().getLastChild();
        if (lastChild != null) {
            lastChild.removeFromParent();
        }/*  w  w w.j  av  a2  s  .c  o  m*/
    }

    this.carriageReturn = carriageReturn;

    final SafeHtml colorOutput = new SafeHtml() {
        @Override
        public String asString() {

            if (Strings.isNullOrEmpty(text)) {
                return " ";
            }

            String encoded = SafeHtmlUtils.htmlEscape(text);
            if (delegate != null) {
                if (delegate.getCustomizer() != null) {
                    if (delegate.getCustomizer().canCustomize(encoded)) {
                        encoded = delegate.getCustomizer().customize(encoded);
                    }
                }
            }

            for (final Pair<RegExp, String> pair : output2Color) {
                final MatchResult matcher = pair.first.exec(encoded);

                if (matcher != null) {
                    return encoded.replaceAll(matcher.getGroup(1),
                            "<span style=\"color: " + pair.second + "\">" + matcher.getGroup(1) + "</span>");
                }
            }

            return encoded;
        }
    };

    PreElement pre = DOM.createElement("pre").cast();
    pre.setInnerSafeHtml(colorOutput);
    if (color != null) {
        pre.getStyle().setColor(color);
    }
    consoleLines.getElement().appendChild(pre);

    followOutput();
}

From source file:org.eclipse.che.ide.ext.svn.client.common.SubversionActionPresenter.java

License:Open Source License

protected void printErrors(final List<String> errors) {
    ensureViewOpened();//from   w w w  .  j  a v  a  2  s  .c  om

    for (final String line : errors) {
        console.print("<span style=\"color:red;\">" + SafeHtmlUtils.htmlEscape(line) + "</span>");
    }
}

From source file:org.eclipse.che.ide.ext.svn.client.common.SubversionActionPresenter.java

License:Open Source License

/**
 * Colorizes and prints response to the output.
 *
 * @param command/*from  ww  w  .ja v a  2 s .  co  m*/
 * @param output
 * @param errors
 */
protected void printResponse(final String command, final List<String> output, final List<String> errors) {
    ensureViewOpened();

    if (command != null) {
        printCommand(command);
    }

    if (output != null) {
        for (final String line : output) {
            boolean found = false;

            if (!line.trim().isEmpty()) {
                String prefix = line.trim().substring(0, 1);

                for (String[] stcol : STATUS_COLORS) {
                    if (stcol[0].equals(prefix)) {
                        // TODO: Turn the file paths into links (where appropriate)
                        console.print("<span style=\"color:" + stcol[1] + ";\">"
                                + SafeHtmlUtils.htmlEscape(line) + "</span>");
                        found = true;
                        break;
                    }
                }
            }

            if (!found) {
                console.print(SafeHtmlUtils.htmlEscape(line));
            }
        }
    }

    if (errors != null) {
        for (final String line : errors) {
            console.print("<span style=\"color:red;\">" + SafeHtmlUtils.htmlEscape(line) + "</span>");
        }
    }

    console.print("");
}