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

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

Introduction

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

Prototype

public SafeHtmlBuilder appendEscaped(String text) 

Source Link

Document

Appends a string after HTML-escaping it.

Usage

From source file:com.google.gwt.sample.showcase.client.content.lists.CwStackLayoutPanel.java

License:Apache License

/**
 * Create the list of Contacts.//w  w w .j a  v  a2  s . c om
 * 
 * @param images the {@link Images} used in the Contacts
 * @return the list of contacts
 */
@ShowcaseSource
private Widget createContactsItem(Images images) {
    // Create a popup to show the contact info when a contact is clicked
    HorizontalPanel contactPopupContainer = new HorizontalPanel();
    contactPopupContainer.setSpacing(5);
    contactPopupContainer.add(new Image(images.defaultContact()));
    final HTML contactInfo = new HTML();
    contactPopupContainer.add(contactInfo);
    final PopupPanel contactPopup = new PopupPanel(true, false);
    contactPopup.setWidget(contactPopupContainer);

    // Create the list of contacts
    VerticalPanel contactsPanel = new VerticalPanel();
    contactsPanel.setSpacing(4);
    String[] contactNames = constants.cwStackLayoutPanelContacts();
    String[] contactEmails = constants.cwStackLayoutPanelContactsEmails();
    for (int i = 0; i < contactNames.length; i++) {
        final String contactName = contactNames[i];
        final String contactEmail = contactEmails[i];
        final Anchor contactLink = new Anchor(contactName);
        contactsPanel.add(contactLink);

        // Open the contact info popup when the user clicks a contact
        contactLink.addClickHandler(new ClickHandler() {
            public void onClick(ClickEvent event) {
                // Set the info about the contact
                SafeHtmlBuilder sb = new SafeHtmlBuilder();
                sb.appendEscaped(contactName);
                sb.appendHtmlConstant("<br><i>");
                sb.appendEscaped(contactEmail);
                sb.appendHtmlConstant("</i>");
                contactInfo.setHTML(sb.toSafeHtml());

                // Show the popup of contact info
                int left = contactLink.getAbsoluteLeft() + 14;
                int top = contactLink.getAbsoluteTop() + 14;
                contactPopup.setPopupPosition(left, top);
                contactPopup.show();
            }
        });
    }
    return new SimplePanel(contactsPanel);
}

From source file:com.google.gwt.sample.validation.server.GreetingServiceImpl.java

License:Apache License

public SafeHtml greetServer(Person person) throws IllegalArgumentException, ConstraintViolationException {
    // Verify that the input is valid.
    Set<ConstraintViolation<Person>> violations = validator.validate(person, Default.class, ServerGroup.class);
    if (!violations.isEmpty()) {
        Set<ConstraintViolation<?>> temp = new HashSet<ConstraintViolation<?>>(violations);
        throw new ConstraintViolationException(temp);
    }/*from w  w  w . ja  v  a 2  s .  c  o m*/

    String serverInfo = getServletContext().getServerInfo();
    String userAgent = getThreadLocalRequest().getHeader("User-Agent");

    // Escape data from the client to avoid cross-site script vulnerabilities.
    SafeHtmlBuilder builder = new SafeHtmlBuilder();

    SafeHtml safeHtml = builder//
            .appendEscapedLines("Hello, " + person.getName() + "!")//
            .appendHtmlConstant("<br>")//
            .appendEscaped("I am running " + serverInfo + ".")//
            .appendHtmlConstant("<br><br>")//
            .appendEscaped("It looks like you are using: ")//
            .appendEscaped(userAgent)//
            .toSafeHtml();
    return safeHtml;
}

From source file:com.google.javascript.jscomp.debugger.gwt.DebuggerGwtMain.java

License:Apache License

private void createCheckboxes(CellPanel checkboxPanel) {
    for (CompilationParam.ParamGroup group : CompilationParam.ParamGroup.values()) {
        SafeHtmlBuilder builder = new SafeHtmlBuilder();
        builder.appendHtmlConstant("<b>");
        builder.appendEscaped(group.name);
        builder.appendHtmlConstant("</b>");

        checkboxPanel.add(new HTML(builder.toSafeHtml()));
        for (final CompilationParam param : CompilationParam.getGroupedSortedValues().get(group)) {
            CheckBox cb = new CheckBox(param.toString());
            if (param.getJavaInfo() != null) {
                cb.setTitle("Java API equivalent: " + param.getJavaInfo());
            }//  ww w . ja v a  2  s  .  com
            cb.setValue(param.getDefaultValue());
            param.apply(options, param.getDefaultValue());
            cb.addClickHandler(new ClickHandler() {
                @Override
                public void onClick(ClickEvent event) {
                    boolean checked = ((CheckBox) event.getSource()).getValue();
                    param.apply(options, checked);
                    doCompile();
                }
            });
            checkboxPanel.add(cb);
        }
    }
}

From source file:com.gsr.myschool.back.client.web.application.session.renderer.AttachedNiveauEtudeTree.java

License:Apache License

@Override
public <T> NodeInfo<?> getNodeInfo(T t) {
    if (t == null) {
        rootDataProvider.setList(treeModel);

        Cell<SessionTree> myCell = new AbstractCell<SessionTree>() {
            @Override/*  ww w .j  ava2  s. c o  m*/
            public void render(Context context, SessionTree value, SafeHtmlBuilder sb) {
                if (value != null) {
                    sb.appendEscaped(value.getName());
                }
            }
        };
        return new DefaultNodeInfo<SessionTree>(rootDataProvider, myCell);
    }

    if (t instanceof SessionTree) {
        SessionTree rootNode = (SessionTree) t;
        ListDataProvider<NiveauEtudeNode> dataProvider = new ListDataProvider<NiveauEtudeNode>();
        ArrayList<NiveauEtudeNode> nodes = new ArrayList<NiveauEtudeNode>(
                rootNode.getNiveauEtudeNodes().values());
        Collections.sort(nodes);
        dataProvider.setList(nodes);

        NiveauEtudeNodeCell niveauEtudeCell = niveauEtudeNodeCellFactory.create(readOnly, detail, delete,
                print);
        return new DefaultNodeInfo<NiveauEtudeNode>(dataProvider, niveauEtudeCell);
    }
    return null;
}

From source file:com.gsr.myschool.back.client.web.application.settings.renderer.MatiereExamenRenderer.java

License:Apache License

@Override
public void render(Context context, MatiereExamenProxy value, SafeHtmlBuilder sb) {
    if (value != null) {
        sb.appendEscaped(value.getNom());
    }/*from ww  w. ja  v a 2  s  .  com*/
}

From source file:com.gsr.myschool.back.client.web.application.settings.renderer.NiveauEtudeInfosTree.java

License:Apache License

@Override
public <T> NodeInfo<?> getNodeInfo(T t) {
    if (t == null) {
        ListDataProvider<FiliereProxy> dataProvider = new ListDataProvider<FiliereProxy>();
        dataProvider.setList(valueList.getFiliereList());
        Cell<FiliereProxy> myCell = new AbstractCell<FiliereProxy>() {
            @Override/*  w  ww  .  j a v  a2 s . c  om*/
            public void render(Context context, FiliereProxy value, SafeHtmlBuilder sb) {
                if (value != null) {
                    sb.appendEscaped(value.getNom());
                }
            }
        };
        return new DefaultNodeInfo<FiliereProxy>(dataProvider, myCell);
    }
    if (t instanceof FiliereProxy) {
        ListDataProvider<NiveauEtudeProxy> dataProvider = new ListDataProvider<NiveauEtudeProxy>();
        dataProvider.setList(valueList.getNiveauEtudeList(((FiliereProxy) t).getId()));
        Cell<NiveauEtudeProxy> myCell = new AbstractCell<NiveauEtudeProxy>(BrowserEvents.DBLCLICK) {
            @Override
            public void render(Context context, NiveauEtudeProxy value, SafeHtmlBuilder sb) {
                if (value != null) {
                    sb.appendEscaped(value.getNom() + "  Age : " + value.getAnnee() + "  Email Convocation : "
                            + (value.getEmailConvocation() == null || !value.getEmailConvocation() ? "NON"
                                    : "OUI"));
                }
            }

            @Override
            public void onBrowserEvent(Context context, Element parent, NiveauEtudeProxy value,
                    NativeEvent event, ValueUpdater<NiveauEtudeProxy> valueUpdater) {
                super.onBrowserEvent(context, parent, value, event, valueUpdater);
                if (value == null) {
                    return;
                }
                if (BrowserEvents.DBLCLICK.equals(event.getType())) {
                    showDetails.execute(value);
                }
            }
        };
        return new DefaultNodeInfo<NiveauEtudeProxy>(dataProvider, myCell);
    }
    return null;
}

From source file:com.gsr.myschool.back.client.web.application.settings.renderer.PieceJustifRenderer.java

License:Apache License

@Override
public void render(Context context, PieceJustifProxy value, SafeHtmlBuilder sb) {
    if (value != null) {
        sb.appendEscaped(value.getNom());
    }//from   www. java 2 s.co  m
}

From source file:com.gsr.myschool.back.client.web.application.settings.widget.EmailTemplateView.java

License:Apache License

@Inject
public EmailTemplateView(final Binder uiBinder, final ValidationErrorPopup errorPopup,
        final SharedMessageBundle sharedMessageBundle, final EmailTemplateEditor emailTemplateEditor,
        final DetailsListStyle listStyle) {
    super(errorPopup);

    this.emailTemplateEditor = emailTemplateEditor;
    this.dataProvider = new ListDataProvider<EmailType>(Arrays.asList(EmailType.values()));
    this.templates = new CellList<EmailType>(new AbstractCell<EmailType>() {
        @Override/*w w w.  j  a v a2  s  .c  om*/
        public void render(Context context, EmailType emailType, SafeHtmlBuilder safeHtmlBuilder) {
            safeHtmlBuilder.appendEscaped(emailType.toString());
        }
    }, listStyle);

    initWidget(uiBinder.createAndBindUi(this));

    dataProvider.addDataDisplay(templates);

    selectionModel = new SingleSelectionModel<EmailType>();
    templates.setSelectionModel(selectionModel);
    templates.getSelectionModel().addSelectionChangeHandler(new SelectionChangeEvent.Handler() {
        @Override
        public void onSelectionChange(SelectionChangeEvent event) {
            EmailType code = selectionModel.getSelectedObject();
            if (code != null)
                getUiHandlers().loadTemplate(code);
        }
    });
    templates.setEmptyListWidget(new EmptyResult(sharedMessageBundle.noResultFound(), AlertType.WARNING));
    selectionModel.setSelected(EmailType.REGISTRATION, true);
}

From source file:com.gwt2go.dev.client.ui.widget.celltree.CellTreeRooterModel.java

License:Apache License

@Override
public <T> NodeInfo<?> getNodeInfo(T value) {
    if (value == null) {
        // Create a data provider that contains the list of composers
        ListDataProvider<CellTreeRooterDaoComposer> dataProvider = new ListDataProvider<CellTreeRooterDaoComposer>(
                composers);/*ww  w.  j a  va2s .c om*/

        // Create a cell to display
        Cell<CellTreeRooterDaoComposer> cell = new AbstractCell<CellTreeRooterDaoComposer>() {
            @Override
            public void render(Context context, CellTreeRooterDaoComposer value, SafeHtmlBuilder sb) {
                if (value != null) {
                    sb.appendEscaped(value.getName());
                }
            }
        };

        // Return a node info that pairs the data provider and the cell
        return new DefaultNodeInfo<CellTreeRooterDaoComposer>(dataProvider, cell);

    } else if (value instanceof CellTreeRooterDaoComposer) {

        // get the first sub level
        ListDataProvider<CellTreeRooterDaoModel> dataProvider = new ListDataProvider<CellTreeRooterDaoModel>(
                ((CellTreeRooterDaoComposer) value).getSubNodes());

        Cell<CellTreeRooterDaoModel> cell = new AbstractCell<CellTreeRooterDaoModel>() {
            @Override
            public void render(Context context, CellTreeRooterDaoModel value, SafeHtmlBuilder sb) {
                if (value != null) {
                    sb.appendEscaped(value.getName());
                }
            }
        };

        return new DefaultNodeInfo<CellTreeRooterDaoModel>(dataProvider, cell);

    } else if (value instanceof CellTreeRooterDaoModel) {

        // get the third sub level
        ListDataProvider<GotoPlacesModel> dataProvider = new ListDataProvider<GotoPlacesModel>(
                ((CellTreeRooterDaoModel) value).getNodes());

        // Use the shared selection model
        return new DefaultNodeInfo<GotoPlacesModel>(dataProvider, new CellTreeRooterCell(), selectionModel,
                null);

    }

    return null;

}

From source file:com.gwt2go.dev.client.ui.widget.celltree.CustomTreeModel.java

License:Apache License

@Override
public <T> NodeInfo<?> getNodeInfo(T value) {
    if (value == null) {
        // Create a data provider that contains the list of composers
        ListDataProvider<CellTreeModelComposer> dataProvider = new ListDataProvider<CellTreeModelComposer>(
                composers);//from  ww  w. ja va2 s .  c o m

        // Create a cell to display
        Cell<CellTreeModelComposer> cell = new AbstractCell<CellTreeModelComposer>() {
            @Override
            public void render(Context context, CellTreeModelComposer value, SafeHtmlBuilder sb) {
                if (value != null) {
                    sb.appendEscaped(value.getName());
                }
            }
        };

        // Return a node info that pairs the data provider and the cell
        return new DefaultNodeInfo<CellTreeModelComposer>(dataProvider, cell);

    } else if (value instanceof CellTreeModelComposer) {
        // get the first sub level
        ListDataProvider<CellTreeDAOModel> dataProvider = new ListDataProvider<CellTreeDAOModel>(
                ((CellTreeModelComposer) value).getSubLists());
        Cell<CellTreeDAOModel> cell = new AbstractCell<CellTreeDAOModel>() {
            @Override
            public void render(Context context, CellTreeDAOModel value, SafeHtmlBuilder sb) {
                if (value != null) {
                    sb.appendEscaped(value.getName());
                }
            }
        };

        return new DefaultNodeInfo<CellTreeDAOModel>(dataProvider, cell);

    } else if (value instanceof CellTreeDAOModel) {
        // get the third sub level
        ListDataProvider<String> dataProvider = new ListDataProvider<String>(
                ((CellTreeDAOModel) value).getSubLevels());

        // Use the shared selection model
        return new DefaultNodeInfo<String>(dataProvider, new TextCell(), selectionModel, null);
    }

    return null;
}