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

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

Introduction

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

Prototype

public static SafeHtml fromString(String s) 

Source Link

Document

Returns a SafeHtml containing the escaped string.

Usage

From source file:tv.dyndns.kishibe.qmaclone.client.packet.PacketProblemCreationLog.java

License:Open Source License

public SafeHtml getPlayer() {
    return SafeHtmlUtils.fromString(name + Utility.makeTrip(userCode, ip));
}

From source file:uk.ac.ncl.openlab.intake24.client.survey.prompts.AutomaticAssociatedFoodsPrompt.java

License:Apache License

@Override
public SurveyStageInterface getInterface(final Callback1<MealOperation> onComplete,
        Callback1<Function1<Meal, Meal>> updateIntermediateState) {
    final FlowPanel content = new FlowPanel();
    PromptUtil.addBackLink(content);/*w  w w  . j  a va  2 s . c o  m*/

    final FlowPanel promptPanel = WidgetFactory.createPromptPanel(SafeHtmlUtils.fromSafeConstant(
            messages.assocFoods_automaticPrompt(SafeHtmlUtils.htmlEscape(meal.name.toLowerCase()))));

    content.add(promptPanel);

    final LoadingPanel loading = new LoadingPanel(messages.foodBrowser_loadingMessage());

    content.add(loading);

    final ArrayList<FoodHeader> encodedFoods = new ArrayList<>();
    final ArrayList<String> foodCodes = new ArrayList<>();

    for (FoodEntry e : meal.foods) {
        if (e.isEncoded()) {

            EncodedFood ef = e.asEncoded();

            encodedFoods.add(new FoodHeader(ef.data.code, ef.data.localDescription));
            foodCodes.add(ef.data.code);
        }
    }

    FoodDataService.INSTANCE.getAutomaticAssociatedFoods(locale, foodCodes,
            new MethodCallback<AutomaticAssociatedFoods>() {
                @Override
                public void onFailure(Method method, Throwable exception) {
                    content.remove(loading);
                    content.add(WidgetFactory.createDefaultErrorMessage());
                }

                @Override
                public void onSuccess(Method method, AutomaticAssociatedFoods response) {
                    content.remove(loading);

                    final List<CheckBox> checkBoxes = new ArrayList<>();
                    final Map<CheckBox, CategoryHeader> foodMap = new LinkedHashMap<>();

                    List<CategoryHeader> categories = response.categories.stream()
                            .filter(c -> milkIsRerevant(c)).collect(Collectors.toList());

                    List<String> codes = categories.stream().map(c -> c.code).collect(Collectors.toList());

                    if (!cachedAssociatedFoodsChanged(codes) || codes.size() == 0) {
                        cacheAssociatedFoods(listToJsArray(new ArrayList<>()));
                        onComplete.call(MealOperation.update(m -> m.markAssociatedFoodsComplete()));
                    } else {
                        cacheAssociatedFoods(listToJsArray(codes));
                        UxEventsHelper.postAutomaticAssociatedFoodsReceived(new AutomaticData(
                                Viewport.getCurrent(), encodedFoods, response.categories, new ArrayList<>()));
                    }

                    for (CategoryHeader category : categories) {
                        CheckBox cb = new CheckBox(SafeHtmlUtils.fromString(category.description()));

                        FlowPanel div = new FlowPanel();
                        div.getElement().getStyle().setPaddingBottom(4, Style.Unit.PX);
                        div.add(cb);
                        cb.getElement().getFirstChildElement().getStyle().setMargin(0, Style.Unit.PX);
                        content.add(div);

                        checkBoxes.add(cb);
                        foodMap.put(cb, category);
                    }

                    Button continueButton = WidgetFactory.createGreenButton("Continue", "continue-button",
                            new ClickHandler() {
                                @Override
                                public void onClick(ClickEvent clickEvent) {

                                    ArrayList<String> selectedCategories = new ArrayList<>();

                                    for (CheckBox cb : checkBoxes) {
                                        if (cb.getValue()) {
                                            selectedCategories.add(foodMap.get(cb).code);
                                        }
                                    }

                                    UxEventsHelper.postAutomaticAssociatedFoodsResponse(
                                            new AutomaticData(Viewport.getCurrent(), encodedFoods,
                                                    response.categories, selectedCategories));

                                    onComplete.call(MealOperation.update(m -> {
                                        List<FoodEntry> newFoodEntries = new ArrayList<>();

                                        for (CheckBox cb : checkBoxes) {
                                            if (cb.getValue()) {
                                                Optional<FoodEntry> assocFood;
                                                CategoryHeader ch = foodMap.get(cb);
                                                switch (ch.code) {
                                                case SpecialData.FOOD_CODE_MILK_ON_CEREAL:
                                                    assocFood = meal.foods.stream()
                                                            .filter(f -> isCerealWithMilk(f)).findFirst();
                                                    if (assocFood.isPresent()) {
                                                        addFood(newFoodEntries, ch, assocFood);
                                                    }
                                                    break;
                                                case SpecialData.FOOD_CODE_MILK_IN_HOT_DRINK:
                                                    assocFood = meal.foods.stream()
                                                            .filter(f -> isHotDrinkWithMilk(f)).findFirst();
                                                    if (assocFood.isPresent()) {
                                                        addFood(newFoodEntries, ch, assocFood);
                                                    }
                                                    break;
                                                default:
                                                    addFood(newFoodEntries, ch, Optional.empty());
                                                    break;

                                                }
                                            }
                                        }

                                        if (newFoodEntries.size() > 0) {
                                            return m.withFoods(m.foods.plusAll(newFoodEntries));
                                        } else {
                                            cacheAssociatedFoods(listToJsArray(new ArrayList<>()));
                                            return m.withFoods(m.foods.plusAll(newFoodEntries))
                                                    .markAssociatedFoodsComplete();
                                        }

                                    }));
                                }
                            });

                    content.add(WidgetFactory.createButtonsPanel(continueButton));
                }
            });

    return new SurveyStageInterface.Aligned(content, HasHorizontalAlignment.ALIGN_LEFT,
            HasVerticalAlignment.ALIGN_TOP, SurveyStageInterface.DEFAULT_OPTIONS,
            AutomaticAssociatedFoodsPrompt.class.getSimpleName());
}

From source file:us.softoption.proofs.TProofCustomCell.java

License:Open Source License

public void renderString(String valueStr, SafeHtmlBuilder sb) {

    //There are some special cases   
    {//from   ww w  . j a  v a2 s  . c om

        SafeHtml safeValue = SafeHtmlUtils.fromString(valueStr); // make the unchanged valueStr safe
        sb.append(safeValue); // not a TGWT node   

    }

}

From source file:us.softoption.tree.TTreeCustomCell.java

License:Open Source License

@Override
public void render(Context context, /*String*/Object value, SafeHtmlBuilder sb) {
    /*//w ww .j a va2 s.c om
     * Always do a null check on the value. Cell widgets can pass null to
     * cells if the underlying data contains a null, or if the data arrives
     * out of order.
     */
    if (value == null) {
        return;
    }

    //value= "<div>"+value+"</div>";

    // If the value comes from the user, we escape it to avoid XSS attacks
    String valueStr = value.toString();

    SafeHtml safeValue;
    /*
          // Use the template to create the Cell's html.
          SafeStyles styles = SafeStylesUtils.fromTrustedString(safeValue.asString());
          SafeHtml rendered = templates.cell(styles, safeValue);
          sb.append(rendered); 
          */

    /*Quite a lot can happen next, there are TestNodes and other things (numbers and strings)*/

    if (value instanceof TGWTTestNode) { // right now we have the formula as a string

        if (((TGWTTestNode) value).fLabelOnly)
            renderLabel((TGWTTestNode) value, sb); // let someone else do it
        else {
            //if it is dead tick it 
            if (((TGWTTestNode) value).fDead)
                valueStr += squareRoot; // tick the dead ones    

            //if it is closed cross it 

            if (((TGWTTestNode) value).fClosed)
                valueStr += largeX; // cross at bottom of closed branch

            // valueStr=padding+valueStr;       //pad it
            safeValue = SafeHtmlUtils.fromString(valueStr); //make it safe

            if (((TGWTTestNode) value).fSelected) {
                SafeHtml rendered = templates.cell(safeValue); //This colors it red
                sb.append(rendered /*safeValue*/);
            } else
                sb.append(safeValue); // Just draw ifnot selected, not red
        }
    } else // not one of our testnodes at all

    {
        renderString(valueStr, sb);

        /* SafeHtml mfSafeValue = SafeHtmlUtils.fromString("<canvas id=\"c\" style=\"border: 1px solid #F00;\" width=\"200\" height=\"200\"></canvas>");
                
              SafeStyles styles = SafeStylesUtils.fromTrustedString(mfSafeValue.asString());
              SafeHtml rendered = mfTemplates.cell(mfSafeValue);
        */

        //String experiment = "<canvas id=\"c\" style=\"border: 1px solid #F00;\" width=\"200\" height=\"200\"></canvas>";

        /*      if (valueStr.equals("Horizontal"))
                 valueStr="";
                     
                      
             safeValue = SafeHtmlUtils.fromString(valueStr); // make the unchanged valueStr safe
             sb.append(safeValue);              // not a TGWT node
                      
             // sb.append(rendered);              // not a TGWT node */

        // ("<img src=\"" + value +"\" />");
    }
}

From source file:us.softoption.tree.TTreeCustomCell.java

License:Open Source License

public void renderString(String valueStr, SafeHtmlBuilder sb) {

    //There are some special cases   

    if (valueStr.equals("Center"))
        ; //sb.appendHtmlConstant(svgWild/*svgCenter*/);
    else if (valueStr.equals("Horizontal")) {
        //valueStr="";
        sb.appendHtmlConstant(svgHorizontal);
        //   SafeHtml safeValue = SafeHtmlUtils.fromString(svgHorizontal); // make the unchanged valueStr safe
        //   sb.append(safeValue);              // not a TGWT node   

    } else if (valueStr.equals("Vertical")) {
        sb.appendHtmlConstant(svgVertical);

    } else if (valueStr.equals("LeftDiag")) {
        sb.appendHtmlConstant(svgLeftDiag);

    } else if (valueStr.equals("RightDiag")) {
        sb.appendHtmlConstant(svgRightDiag);

    } else {/*  w  ww.  ja v a  2s.co  m*/

        SafeHtml safeValue = SafeHtmlUtils.fromString(valueStr); // make the unchanged valueStr safe
        sb.append(safeValue); // not a TGWT node   

    }

}