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:org.mklab.taskit.client.ui.cell.SelectCell.java

License:Apache License

/**
 * {@inheritDoc}//from  w  w w  . j  a  va2  s .  c  o  m
 */
@SuppressWarnings("nls")
@Override
public void render(@SuppressWarnings("unused") com.google.gwt.cell.client.Cell.Context context, E value,
        SafeHtmlBuilder sb) {
    if (this.editable) {
        sb.appendHtmlConstant("<select>");
    } else {
        int index = 0;
        for (E option : this.options) {
            final boolean selected = this.comparator.equals(option, value);
            if (selected) {
                final String escapedOption = SafeHtmlUtils.htmlEscape(this.renderer.render(index++, option));
                sb.appendEscaped(escapedOption);
            }
        }
        return;
    }

    int index = 0;
    for (E option : this.options) {
        final boolean selected = this.comparator.equals(option, value);
        final String escapedOption = SafeHtmlUtils.htmlEscape(this.renderer.render(index++, option));
        sb.appendHtmlConstant("<option value='" + escapedOption + "'" + (selected ? " selected" : "") + ">"
                + escapedOption + "</option>");
    }
    sb.appendHtmlConstant("</select>");
}

From source file:org.opencms.ade.sitemap.client.alias.CmsCellTableUtil.java

License:Open Source License

/**
 * Formats the HTML for the error column of a cell table given an error message.<p>
 *
 * @param error the error message (null for no error)
 *
 * @return the SafeHtml representing the contents of the error cell
 *///  w w w.  j  ava 2s .  c om
public static SafeHtml formatErrorHtml(String error) {

    String text;
    String cssClass;
    String title = "";

    if (error == null) {
        text = CmsAliasMessages.messageStatusOk();
        cssClass = STATUS_OK;
    } else {
        text = CmsAliasMessages.messageStatusError();
        title = SafeHtmlUtils.htmlEscape(error);
        cssClass = STATUS_ERROR;
    }
    String html = "<div class='" + cssClass + "' title='" + title + "'>" + text + "</div>";
    return SafeHtmlUtils.fromSafeConstant(html);
}

From source file:org.opendatakit.dwc.client.DemoWebClient.java

License:Apache License

private void defineDialogIneractions(final TextBox nameField, final Button sendButton, final Label errorLabel,
        final BUTTON_FIELD_ACTION api) {

    // Create the popup dialog box
    final DialogBox dialogBox = new DialogBox();
    dialogBox.setText("Remote Procedure Call");
    dialogBox.setAnimationEnabled(true);
    final Button closeButton = new Button("Close");
    // We can set the id of a widget by accessing its Element
    closeButton.getElement().setId("closeButton");
    final Label textToServerLabel = new Label();
    final HTML serverResponseLabel = new HTML();
    VerticalPanel dialogVPanel = new VerticalPanel();
    dialogVPanel.addStyleName("dialogVPanel");
    dialogVPanel.add(new HTML("<b>Sending name to the server:</b>"));
    dialogVPanel.add(textToServerLabel);
    dialogVPanel.add(new HTML("<br><b>Server replies:</b>"));
    dialogVPanel.add(serverResponseLabel);
    dialogVPanel.setWidth(Integer.toString(Window.getClientWidth() - 10) + "px");
    dialogVPanel.setHorizontalAlignment(VerticalPanel.ALIGN_RIGHT);
    dialogVPanel.add(closeButton);/*from w ww  .j  a va 2  s .c  o  m*/
    dialogBox.setWidget(dialogVPanel);

    // Add a handler to close the DialogBox
    closeButton.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent event) {
            dialogBox.hide();
            sendButton.setEnabled(true);
            sendButton.setFocus(true);
        }
    });

    // Create a handler for the sendButton and nameField
    class MyHandler implements ClickHandler, KeyUpHandler {
        /**
         * Fired when the user clicks on the sendButton.
         */
        public void onClick(ClickEvent event) {
            sendNameToServer();
        }

        /**
         * Fired when the user types in the nameField.
         */
        public void onKeyUp(KeyUpEvent event) {
            if (event.getNativeKeyCode() == KeyCodes.KEY_ENTER) {
                sendNameToServer();
            }
        }

        /**
         * Send the name from the nameField to the server and wait for a response.
         */
        private void sendNameToServer() {
            // First, we validate the input.
            errorLabel.setText("");
            String textToServer = nameField.getText();
            if (!FieldVerifier.isValidName(textToServer)) {
                errorLabel.setText("Please enter at least four characters");
                return;
            }

            // Then, we send the input to the server.
            sendButton.setEnabled(false);
            textToServerLabel.setText(textToServer);
            serverResponseLabel.setText("");
            AsyncCallback<String> callback = new AsyncCallback<String>() {
                public void onFailure(Throwable caught) {
                    // Show the RPC error message to the user
                    dialogBox.setText("Remote Procedure Call - Failure");
                    serverResponseLabel.addStyleName("serverResponseLabelError");
                    serverResponseLabel
                            .setHTML("<verbatim>" + SafeHtmlUtils.htmlEscape(SERVER_ERROR) + "</verbatim>");
                    dialogBox.getWidget().setWidth("90%");
                    dialogBox.center();
                    closeButton.setFocus(true);
                }

                public void onSuccess(String result) {
                    dialogBox.setText("Remote Procedure Call");
                    serverResponseLabel.removeStyleName("serverResponseLabelError");
                    serverResponseLabel
                            .setHTML("<verbatim>" + SafeHtmlUtils.htmlEscape(result) + "</verbatim>");
                    dialogBox.getWidget().setWidth("90%");
                    dialogBox.center();
                    closeButton.setFocus(true);
                }
            };

            if (api == BUTTON_FIELD_ACTION.OAUTH2_FETCH) {
                greetingService.obtainOauth2Data(textToServer, callback);
            } else if (api == BUTTON_FIELD_ACTION.OAUTH1_FETCH) {
                greetingService.obtainOauth1Data(textToServer, callback);
            } else {
                greetingService.greetServer(textToServer, callback);
            }
        }
    }

    // Add a handler to send the name to the server
    MyHandler handler = new MyHandler();
    sendButton.addClickHandler(handler);
    nameField.addKeyUpHandler(handler);
}

From source file:org.otalo.ao.client.widget.chlist.client.ChosenImpl.java

License:Apache License

private boolean keyupChecker(Event e) {
    int stroke = e.getKeyCode();

    searchFieldScale();/* ww w . j  a  v a  2 s  .  c  o  m*/

    switch (stroke) {
    case 8: // backspace
        if (isMultiple && backstrokeLength < 1 && choices > 0) {
            keydownBackstroke();
        } else if (pendingBackstroke == null) {
            resultClearHighlight();
            resultsSearch();
        }
        break;

    case 13: // enter
        //if any result is being shown then it should select option from result first
        if (resultsShowing) {
            resultSelect(e);
        }

        //checking if user allows to add new option value
        if (options.isAddNewOptionVal()) {
            //if user is allowing to add new value then getting and checking for searchField value
            String newItemVal = defaultText.equals(searchField.val()) ? "" : searchField.val().trim();
            newItemVal = SafeHtmlUtils.htmlEscape(newItemVal);
            int results = getResults(newItemVal);
            if (results < 1 && newItemVal != null && !newItemVal.isEmpty()) {
                //If already exist into list, don't add it
                if (!isAlreadyExist(newItemVal)) {
                    addNewItem(newItemVal, newItemVal);
                    searchField.val("");
                }
            }
        }
        return true;
    case 27: // escape
        if (resultsShowing) {
            resultsHide();
        }
        return false;
    case 9:
    case 38:
    case 40:
    case 16:
    case 91:
    case 17:
        // do nothing
        break;
    default:
        resultsSearch();
        break;
    }

    return true;
}

From source file:org.otalo.ao.client.widget.chlist.client.ChosenImpl.java

License:Apache License

private void winnowResults() {

    noResultClear();//  w  w  w .  ja  v  a  2s. c om
    String searchText = defaultText.equals(searchField.val()) ? "" : searchField.val().trim();
    searchText = SafeHtmlUtils.htmlEscape(searchText);

    int results = getResults(searchText);

    if (results < 1 && searchText.length() > 0) {
        noResults(searchText);
    } else {
        winnowResultsSetHighlight();
    }
}

From source file:org.ow2.proactive_grid_cloud_portal.common.server.LoginServlet.java

License:Open Source License

private void login(HttpServletRequest request, HttpServletResponse response) {
    response.setContentType("text/html");
    File cred = null;//from ww w .  jav  a2 s  .  co  m
    try {
        DiskFileItemFactory factory = new DiskFileItemFactory();
        factory.setSizeThreshold(4096);
        factory.setRepository(new File(System.getProperty("java.io.tmpdir")));
        ServletFileUpload upload = new ServletFileUpload(factory);
        upload.setSizeMax(1000000);

        List<?> fileItems = upload.parseRequest(request);
        Iterator<?> i = fileItems.iterator();

        String user = "";
        String pass = "";
        String sshKey = "";

        while (i.hasNext()) {
            FileItem fi = (FileItem) i.next();

            if (fi.isFormField()) {
                String name = fi.getFieldName();
                String value = fi.getString();

                if (name.equals("username")) {
                    user = value;
                } else if (name.equals("password")) {
                    pass = value;
                }
            } else {
                String field = fi.getFieldName();

                byte[] bytes = IOUtils.toByteArray(fi.getInputStream());

                if (field.equals("credential")) {
                    cred = File.createTempFile("credential", null);
                    cred.deleteOnExit();
                    fi.write(cred);
                } else if (field.equals("sshkey")) {
                    sshKey = new String(bytes);
                }
            }

            fi.delete();
        }

        String responseS = Service.get().login(user, pass, cred, sshKey);
        String s = "{ \"sessionId\" : \"" + responseS + "\" }";
        response.getWriter().write(SafeHtmlUtils.htmlEscape(s));
    } catch (Throwable t) {
        try {
            response.getWriter().write(SafeHtmlUtils.htmlEscape(t.getMessage()));
        } catch (IOException e1) {
            LOGGER.warn("Failed to return login error to client, error was:" + t.getMessage(), e1);
        }
    } finally {
        if (cred != null)
            cred.delete();
    }
}

From source file:org.ow2.proactive_grid_cloud_portal.scheduler.client.JobOutput.java

License:Open Source License

private String formatLine(String str) {
    if (str.matches("\\[.*\\].*")) {
        str = SafeHtmlUtils.htmlEscape(str).replaceFirst("]", "]</span>");
        return "<nobr><span style='color:gray;'>" + str + "</nobr><br>";
    }/*from  w  w w  .  j  ava 2s. com*/
    return "";
}

From source file:org.pentaho.platform.dataaccess.datasource.DatasourceInfo.java

License:Open Source License

@Bindable
@Override
public String getName() {
    return SafeHtmlUtils.htmlEscape(name);
}

From source file:org.rest.client.ui.desktop.ResponseViewImpl.java

License:Apache License

private void setResponseBody() {
    if (!success || response.getStatus() == 0) {
        return;//from   ww  w . j a v  a  2s .  c  o  m
    }
    //Response does not contain any data.
    final String body = response.getResponseText();
    Document xml = response.getResponseXML();
    boolean isXML = false, isJSON = false, isImage = false;

    String escaped = SafeHtmlUtils.htmlEscape(body);
    boolean useCodeMirror = false;

    if (xml != null) {
        isXML = true;
    }
    Header[] headers = response.getHeaders();
    if (!isXML) {
        //check if response has JSON header:
        if (isJSONHeader(headers)) {
            isJSON = true;
        }
    }
    if (!isJSON && !isXML) {
        //just HTML
        useCodeMirror = true;
    }

    isImage = isImageHeader(headers);
    if (isImage) {
        useCodeMirror = false;
        isJSON = false;
        isXML = false;
    }

    if (escaped.equals("")) {
        xml = null;
        isXML = false;
        Element info = DOM.createSpan();
        info.setInnerText("Response does not contain any data.");
        info.addClassName("note italic");
        plainBody.getElement().appendChild(info);
        setTabOpened(TABS.RAW, rawTab);
        return;
    } else {
        plainBody.setHTML(escaped);
    }

    if (useCodeMirror) {
        setTabOpened(TABS.PARSED, parsedTab);
        //show this tab
        setTabVisible(TABS.PARSED, parsedTab);

        if (RestClient.isDebug()) {
            Log.debug("Initialize code mirror...");
        }
        String _encoding = getRequestContentType("text/html");
        if (_encoding.contains("javascript")) {
            _encoding = "text/javascript";
        }
        final String encoding = _encoding;

        try {
            getRequestDomainAndPath(new Callback<String, Throwable>() {
                @Override
                public void onSuccess(String result) {
                    loadCodeMirror(body, encoding, result);
                }

                @Override
                public void onFailure(Throwable reason) {

                }
            });

        } catch (Exception e) {
            if (RestClient.isDebug()) {
                Log.warn("Unable to load CodeMirror.", e);
            }
        }

        //         if(isJavaScriptHeader(headers)){
        forceOpenAsJSON.removeStyleName("hidden");
        //         }
    }
    if (isJSON) {
        setTabOpened(TABS.JSON, jsonTab);
        new JSONViewer(body, jsonPanel);
        setTabVisible(TABS.JSON, jsonTab);
    }
    if (isXML) {
        setTabOpened(TABS.XML, xmlTab);
        new XMLViewer(body, xmlPanel, xml);
        setTabVisible(TABS.XML, xmlTab);
    }
    if (isImage) {

        //         setTabOpened(TABS.IMAGE, imageTab);
        //         setTabVisible(TABS.IMAGE, imageTab);
        //         final Image img = new Image();
        //         img.addLoadHandler(new LoadHandler() {
        //            @Override
        //            public void onLoad(LoadEvent event) {
        //               revokeImageUrl(img.getUrl());
        //            }
        //         });
        //         img.setUrl(createImageUrl(response.getRequest(),"image/png"));
        //         imagePanel.add(img);
    }
    if (RestClient.isDebug()) {
        Log.debug("Response panel has been filled with new data");
    }
}

From source file:org.roda.wui.client.browse.BitstreamPreview.java

private void textPreview() {
    if (StringUtils.isBlank(viewers.getTextLimit()) || size <= Long.parseLong(viewers.getTextLimit())) {
        RequestBuilder request = new RequestBuilder(RequestBuilder.GET, bitstreamDownloadUri.asString());
        try {/*  ww  w.j  av a 2 s  .co m*/
            request.sendRequest(null, new RequestCallback() {

                @Override
                public void onResponseReceived(Request request, Response response) {
                    if (response.getStatusCode() == HttpStatus.SC_OK) {
                        HTML html = new HTML(
                                "<pre><code>" + SafeHtmlUtils.htmlEscape(response.getText()) + "</code></pre>");
                        FlowPanel frame = new FlowPanel();
                        frame.add(html);

                        panel.add(frame);
                        frame.setStyleName("viewRepresentationTextFilePreview");
                        JavascriptUtils.runHighlighter(html.getElement());
                    } else {
                        errorPreview();
                    }
                }

                @Override
                public void onError(Request request, Throwable exception) {
                    errorPreview();
                }
            });
        } catch (RequestException e) {
            errorPreview();
        }
    } else {
        errorPreview(messages.viewRepresentationTooLargeErrorPreview());
    }
}