Example usage for com.google.gwt.http.client URL encode

List of usage examples for com.google.gwt.http.client URL encode

Introduction

In this page you can find the example usage for com.google.gwt.http.client URL encode.

Prototype

public static String encode(String decodedURL) 

Source Link

Document

Returns a string where all characters that are not valid for a complete URL have been escaped.

Usage

From source file:at.ait.dme.yuma.client.map.annotation.GoogleMapsComposite.java

License:EUPL

/**
 * create the link to export annotations as KML
 * // ww w .  j a v  a 2s  .  c o m
 * @return href
 */
private String createKmlLink() {
    StringBuffer sb = new StringBuffer();

    sb.append("yuma/tokml?url=");
    sb.append(Application.getImageUrl());
    sb.append("&europeanaUri=");
    sb.append(Application.getExternalObjectId());
    sb.append("&a=");

    for (ImageAnnotation annotation : annotations) {
        if (!annotation.hasFragment())
            continue;
        sb.append(AnnotationUtils.shapeToVectorFeature(annotation.getFragment().getShape()).getGeometry()
                .toString());
        sb.append("@" + annotation.getTitle() + "@" + annotation.getText());
        sb.append(";");
    }

    return URL.encode(sb.toString());
}

From source file:at.ait.dme.yuma.suite.apps.map.client.widgets.GoogleMapsComposite.java

License:EUPL

/**
 * create the link to export annotations as KML
 * /*from   w ww .j  av a  2  s. co  m*/
 * @return href
 */
private String createKmlLink() {
    StringBuffer sb = new StringBuffer();

    sb.append("tokml?url=");
    sb.append(YUMACoreProperties.getObjectURI());
    sb.append("&a=");

    for (ImageAnnotation annotation : annotations) {
        if (!annotation.hasFragment())
            continue;
        sb.append(MapUtils.shapeToVectorFeature(((ImageFragment) annotation.getFragment()).getShape())
                .getGeometry().toString());
        sb.append("@" + annotation.getTitle() + "@" + annotation.getText());
        sb.append(";");
    }

    return URL.encode(sb.toString());
}

From source file:bufferings.ktr.wjr.client.service.KtrWjrJsonServiceAsync.java

License:Apache License

/**
 * Returns a String that is suitable for use as an
 * <code>application/x-www-form-urlencoded</code> list of parameters in an
 * HTTP PUT or HTTP POST./* w w  w . ja  va 2 s.  c o  m*/
 * 
 * @param parameters
 *          The parameters to include.
 * @param encoding
 *          The encoding to use.
 */
String format(List<Pair> parameters) {
    final StringBuilder result = new StringBuilder();
    for (final Pair parameter : parameters) {
        String encodedName = URL.encode(parameter.name);
        String encodedValue = parameter.value != null ? URL.encode(parameter.value) : "";
        if (result.length() > 0) {
            result.append(PARAMETER_SEPARATOR);
        }
        result.append(encodedName);
        result.append(NAME_VALUE_SEPARATOR);
        result.append(encodedValue);
    }
    return result.toString();
}

From source file:cc.kune.core.client.sitebar.search.MultivalueSuggestBox.java

License:GNU Affero Public License

/**
 * Retrieve Options (name-value pairs) that are suggested from the REST
 * endpoint//from   ww  w  .j ava2s  .c o  m
 * 
 * @param query
 *          - the String search term
 * @param from
 *          - the 0-based begin index int
 * @param to
 *          - the end index inclusive int
 * @param callback
 *          - the OptionQueryCallback to handle the response
 */
private void queryOptions(final String query, final int from, final int to,
        final OptionQueryCallback callback) {
    final RequestBuilder builder = new RequestBuilder(RequestBuilder.GET,
            URL.encode(mrestEndpointUrl + "?" + SearcherConstants.QUERY_PARAM + "=" + query + "&"
                    + SearcherConstants.START_PARAM + "=" + from + "&" + SearcherConstants.LIMIT_PARAM + "="
                    + PAGE_SIZE));

    // Set our headers
    builder.setHeader("Accept", "application/json; charset=utf-8");

    // Fails on chrome
    // builder.setHeader("Accept-Charset", "UTF-8");

    builder.setCallback(new RequestCallback() {

        @Override
        public void onError(final com.google.gwt.http.client.Request request, final Throwable exception) {
            callback.error(exception);
        }

        @Override
        public void onResponseReceived(final com.google.gwt.http.client.Request request,
                final Response response) {
            final JSONValue val = JSONParser.parse(response.getText());
            final JSONObject obj = val.isObject();
            final int totSize = (int) obj.get(OptionResultSet.TOTAL_SIZE).isNumber().doubleValue();
            final OptionResultSet options = new OptionResultSet(totSize);
            final JSONArray optionsArray = obj.get(OptionResultSet.OPTIONS).isArray();

            if (options.getTotalSize() > 0 && optionsArray != null) {

                for (int i = 0; i < optionsArray.size(); i++) {
                    if (optionsArray.get(i) == null) {
                        /*
                         * This happens when a JSON array has an invalid trailing comma
                         */
                        continue;
                    }

                    final JSONObject jsonOpt = optionsArray.get(i).isObject();
                    final Option option = new Option();

                    final String longName = jsonOpt.get(OptionResultSet.DISPLAY_NAME).isString().stringValue();
                    final String shortName = jsonOpt.get(OptionResultSet.VALUE).isString().stringValue();
                    final JSONValue groupTypeJsonValue = jsonOpt.get("groupType");
                    final String prefix = groupTypeJsonValue.isString() == null ? ""
                            : GroupType.PERSONAL.name().equals(groupTypeJsonValue.isString().stringValue())
                                    ? I18n.t("User") + ": "
                                    : I18n.t("Group") + ": ";
                    option.setName(prefix
                            + (!longName.equals(shortName) ? longName + " (" + shortName + ")" : shortName));
                    option.setValue(jsonOpt.get(OptionResultSet.VALUE).isString().stringValue());
                    options.addOption(option);
                }
            }
            callback.success(options);
        }
    });

    try {
        if (lastQuery != null && lastQuery.isPending()) {
            lastQuery.cancel();
        }
        lastQuery = builder.send();
    } catch (final RequestException e) {
        updateFormFeedback(FormFeedback.ERROR, "Error: " + e.getMessage());
    }

}

From source file:ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.data.DataSetUploadForm.java

License:Apache License

private static String encodeCifexRequest(String cifexUrl, String recipient, String comment) {
    URLMethodWithParameters url = new URLMethodWithParameters(cifexUrl);
    url.addParameter(BasicConstant.CIFEX_URL_PARAMETER_COMMENT, comment);
    url.addParameter(BasicConstant.CIFEX_URL_PARAMETER_RECIPIENT, recipient);
    return URL.encode(url.toString());
}

From source file:cl.uai.client.MarkingInterface.java

License:Open Source License

public void updateGeneralFeedback(final String generalFeedback) {
    addLoading(true);/*from  w ww.  java2 s . c  o  m*/
    // Invokes the ajax Moodle interface to save the mark
    AjaxRequest.ajaxRequest("action=updgeneralfeedback" + "&feedback=" + URL.encode(generalFeedback),
            new AsyncCallback<AjaxData>() {
                @Override
                public void onSuccess(AjaxData result) {
                    // Parse json results and check if there was an error
                    if (!result.getError().equals("")) {
                        logger.severe(result.getError());
                        Window.alert(result.getError());
                        return;
                    }

                    finishLoading();
                }

                @Override
                public void onFailure(Throwable caught) {
                    if (EMarkingConfiguration.isDebugging()) {
                        caught.printStackTrace();
                        logger.severe(caught.getMessage());
                    }
                    finishLoading();
                }
            });
}

From source file:cl.uai.client.MarkingInterface.java

License:Open Source License

/**
 * Add a mark to both the page and update the rubric interface
 * /*from  w ww .  j  a  v  a2s.  c  o  m*/
 * @param mark the mark to add
 */
public void addMark(final Mark mark, final MarkingPage page) {

    RootPanel.get().getElement().getStyle().setCursor(Cursor.WAIT);

    Mark.loadingIcon.removeFromParent();
    page.getAbsolutePanel().add(Mark.loadingIcon, mark.getPosx(), mark.getPosy());
    Mark.loadingIcon.setVisible(true);

    //por defecto el criterionid = 0 y la clase para el color es criterion0
    int cid = 0;
    if (EMarkingConfiguration.isColoredRubric()) {
        Criterion c = EMarkingWeb.markingInterface.getToolbar().getMarkingButtons().getSelectedCriterion();
        if (c != null) {
            cid = c.getId();
        }
    }

    int markposx = mark.getPosx();
    int markposy = mark.getPosy();

    String path = "";
    if (mark instanceof HighlightMark) {
        HighlightMark hmark = (HighlightMark) mark;
        path = "&path=" + URL.encode(hmark.getEnd().getX() + "," + hmark.getEnd().getY());
        logger.fine("sending " + markposx + "," + markposy + " -> " + hmark.getEnd().getX() + ","
                + hmark.getEnd().getY() + " path:" + path);
    } else if (mark instanceof PathMark) {
        path = "&path=" + URL.encode(((PathMark) mark).getPath());
    }
    // Invokes the ajax Moodle interface to save the mark
    AjaxRequest.ajaxRequest("action=addcomment" + "&comment=" + URL.encode(mark.getRawtext()) + "&posx="
            + markposx + "&posy=" + markposy + "&width=" + page.getWidth() + "&height=" + page.getHeight()
            + "&format=" + mark.getFormat() + "&pageno=" + mark.getPageno() + "&criterionid=" + cid + path
            + "&colour=" + mark.getCriterionId() + "&windowswidth=" + page.getWidth() + "&windowsheight="
            + page.getHeight(), new AsyncCallback<AjaxData>() {

                @Override
                public void onFailure(Throwable caught) {
                    Mark.loadingIcon.setVisible(false);
                    logger.severe("Exception adding mark.");
                    logger.severe(caught.getMessage());
                    Window.alert(caught.getMessage());
                    RootPanel.get().getElement().getStyle().setCursor(Cursor.AUTO);
                }

                @Override
                public void onSuccess(AjaxData result) {
                    Mark.loadingIcon.setVisible(false);

                    Map<String, String> values = AjaxRequest.getValueFromResult(result);

                    // Parse json results and check if there was an error
                    if (!result.getError().equals("")) {
                        Window.alert(messages.ErrorAddingMark());
                        RootPanel.get().getElement().getStyle().setCursor(Cursor.AUTO);
                        return;
                    }

                    // Parses important values from result
                    int id = Integer.parseInt(values.get("id"));
                    long timemodified = Long.parseLong(values.get("timemodified"));
                    int markerid = Integer.parseInt(values.get("markerid"));
                    String markername = values.get("markername");
                    float newgrade = 0;
                    if (mark instanceof RubricMark) {
                        newgrade = Float.parseFloat(values.get("grade"));
                    } else {
                        newgrade = MarkingInterface.submissionData.getFinalgrade();
                    }

                    // Sets the values for the new mark
                    mark.setId(id);
                    mark.setMarkerid(markerid);
                    mark.setMarkername(markername);
                    mark.setTimeCreated(timemodified);

                    // Adds the mark to the marking interface
                    markingPagesInterface.addMarkWidget(mark, -1, page);

                    // If it is a comment And to the rubric interface
                    toolbar.getMarkingButtons().updateStats();

                    if (!(mark instanceof CustomMark) && mark.getFormat() != 5) {
                        EMarkingWeb.markingInterface.getRubricInterface().getToolsPanel().getPreviousComments()
                                .addMarkAsCommentToInterface(mark, true);
                    }

                    // Updates toolbar
                    setTimemodified(timemodified);

                    // Update the marking interface with the final grade and time
                    EMarkingWeb.markingInterface.setFinalgrade(newgrade, timemodified);

                    RootPanel.get().getElement().getStyle().setCursor(Cursor.AUTO);
                }
            });

}

From source file:cl.uai.client.MarkingInterface.java

License:Open Source License

/**
 * Adds a mark to current submission./*from  w w  w  . j a  v a  2s  .  co m*/
 * 
 * @param level the mark to assign
 * @param posx X coordinate where to draw mark in page
 * @param posy Y coordinate where to draw mark in page
 */
public void addRubricMark(final int level, final int posx, final int posy, final MarkingPage page) {

    // Shows comment dialog
    // 0 for regradeid as we are creating a mark
    final EditMarkDialog dialog = new EditMarkDialog(posx, posy, level, 0);
    if (this.setBonus >= 0) {
        dialog.setBonus(this.setBonus);
        this.setBonus = -1;
    }
    dialog.addCloseHandler(new CloseHandler<PopupPanel>() {
        @Override
        public void onClose(CloseEvent<PopupPanel> event) {

            // If dialog was not cancelled and contains a comment, try to add the mark
            if (!dialog.isCancelled()) {

                // Calculate parameters for adding mark
                final String comment = dialog.getTxtComment(); // Comment from dialog
                final float bonus = dialog.getBonus();
                final int levelid = dialog.getLevelId();
                final String feedbackToAjax;
                if (dialog.haveFeedback()) {
                    feedbackToAjax = dialog.getFeedback();
                } else {
                    feedbackToAjax = "";
                }
                // Ajax URL for adding mark
                String url = "action=addmark" + "&level=" + levelid + "&posx=" + posx + "&posy=" + posy
                        + "&pageno=" + (page.getPageNumber()) + "&sesskey=" + EMarkingConfiguration.getSessKey()
                        + "&bonus=" + bonus + "&comment=" + URL.encode(comment) + "&windowswidth="
                        + page.getWidth() + "&windowsheight=" + page.getHeight() + "&feedback="
                        + feedbackToAjax;

                // Add loading icon
                Mark.loadingIcon.removeFromParent();
                page.getAbsolutePanel().add(Mark.loadingIcon, posx, posy);
                Mark.loadingIcon.setVisible(true);

                rubricInterface.getRubricPanel().loadingRubricCriterion(levelid);

                // Make Ajax request 
                AjaxRequest.ajaxRequest(url, new AsyncCallback<AjaxData>() {

                    @Override
                    public void onFailure(Throwable caught) {
                        Mark.loadingIcon.setVisible(false);
                        rubricInterface.getRubricPanel().finishloadingRubricCriterion(levelid);

                        logger.severe("Error adding mark to Moodle!");
                        logger.severe(caught.getMessage());
                        Window.alert(caught.getMessage());
                    }

                    @Override
                    public void onSuccess(AjaxData result) {
                        Mark.loadingIcon.setVisible(false);
                        rubricInterface.getRubricPanel().finishloadingRubricCriterion(levelid);
                        Mark.hideIcons();

                        // Parse Json values
                        Map<String, String> values = AjaxRequest.getValueFromResult(result);

                        if (!values.get("error").equals("")) {
                            Mark.loadingIcon.setVisible(false);
                            rubricInterface.getRubricPanel().finishloadingRubricCriterion(levelid);

                            logger.severe("Error adding mark to Moodle!");
                            Window.alert(MarkingInterface.messages.ErrorAddingMark());
                            return;
                        }

                        // Get main values
                        int previd = Integer.parseInt(values.get("replaceid"));
                        int newid = Integer.parseInt(values.get("id"));
                        float newgrade = Float.parseFloat(values.get("grade"));
                        long timemodified = Long.parseLong(values.get("timemodified"));
                        String markername = values.get("markername");
                        int pageno = page.getPageNumber();
                        int regradeid = Integer.parseInt(values.get("regradeid"));
                        int regradeaccepted = Integer.parseInt(values.get("regradeaccepted"));
                        int regrademotive = Integer.parseInt(values.get("regrademotive"));
                        String regradecomment = values.get("regradecomment");
                        String regrademarkercomment = values.get("regrademarkercomment");
                        int criterionId = Integer.parseInt(values.get("criterionid"));

                        // If there was a previous mark with the same level, remove it
                        if (previd > 0) {
                            page.deleteMarkWidget(previd);
                        }

                        long unixtime = System.currentTimeMillis() / 1000L;

                        // Add mark to marking pages interface
                        RubricMark mark = new RubricMark(newid, posx, posy, pageno,
                                EMarkingConfiguration.getMarkerId(), dialog.getLevelId(), unixtime, criterionId,
                                markername, comment);

                        if (dialog.haveFeedback()) {
                            mark.setFeedback(dialog.getFeedbackArray());
                        }
                        mark.setRegradeid(regradeid);
                        mark.setRegradeaccepted(regradeaccepted);
                        mark.setRegradecomment(regradecomment);
                        mark.setRegrademarkercomment(regrademarkercomment);
                        mark.setRegrademotive(regrademotive);

                        Criterion criterion = MarkingInterface.submissionData.getLevelById(mark.getLevelId())
                                .getCriterion();
                        criterion.setSelectedLevel(mark.getLevelId());
                        criterion.setBonus(bonus);
                        markingPagesInterface.addMarkWidget(mark, previd, page);
                        rubricInterface.getRubricPanel().addMarkToRubric(mark);
                        toolbar.getMarkingButtons().updateStats();
                        toolbar.getMarkingButtons().changeColor(criterion.getId());

                        EMarkingWeb.markingInterface.getRubricInterface().getToolsPanel().getPreviousComments()
                                .addMarkAsCommentToInterface(mark, true);

                        setFinalgrade(newgrade, timemodified);
                    }
                });
            }
        }
    });
    dialog.center();
}

From source file:cl.uai.client.MarkingInterface.java

License:Open Source License

public void regradeMark(final RubricMark mark, final String comment, final int motive) {

    RootPanel.get().getElement().getStyle().setCursor(Cursor.WAIT);
    final MarkingPage page = markingPagesInterface.getPageByIndex(mark.getPageno() - 1);
    if (page == null) {
        logger.severe("Page is null for page index " + mark.getPageno());
        return;// ww  w .j a v  a2  s .  c  o m
    }
    Mark.loadingIcon.removeFromParent();
    page.getAbsolutePanel().add(Mark.loadingIcon, mark.getPosx(), mark.getPosy());
    Mark.loadingIcon.setVisible(true);

    // Invokes the ajax Moodle interface to save the mark
    AjaxRequest.ajaxRequest("action=addregrade" + "&comment=" + URL.encode(comment) + "&motive=" + motive
            + "&level=" + mark.getLevelId(), new AsyncCallback<AjaxData>() {

                @Override
                public void onFailure(Throwable caught) {
                    Mark.loadingIcon.setVisible(false);
                    logger.severe("Exception regrading mark.");
                    logger.severe(caught.getMessage());
                    Window.alert(caught.getMessage());
                    RootPanel.get().getElement().getStyle().setCursor(Cursor.AUTO);
                }

                @Override
                public void onSuccess(AjaxData result) {
                    Mark.loadingIcon.setVisible(false);

                    Map<String, String> values = AjaxRequest.getValueFromResult(result);

                    // Parse json results and check if there was an error
                    if (!result.getError().equals("")) {
                        Window.alert(messages.ErrorAddingMark());
                        RootPanel.get().getElement().getStyle().setCursor(Cursor.AUTO);
                        return;
                    }

                    // Parses important values from result
                    int regradeid = Integer.parseInt(values.get("regradeid"));
                    long timemodified = Long.parseLong(values.get("timemodified"));

                    // Sets the values for the new mark
                    mark.setRegradeid(regradeid);
                    mark.setRegradecomment(comment);
                    mark.setRegrademotive(motive);

                    // Add the mark to the rubric so it updates the information in the rubric panel
                    EMarkingWeb.markingInterface.getRubricInterface().getRubricPanel().addMarkToRubric(mark);
                    mark.setMarkHTML();

                    // Updates toolbar
                    setTimemodified(timemodified);

                    RootPanel.get().getElement().getStyle().setCursor(Cursor.AUTO);
                }
            });
}

From source file:cl.uai.client.marks.Mark.java

License:Open Source License

/**
 * Updates a mark's comment, position or bonus
 * //  ww  w .  ja v  a2  s  .c o m
 * @param newcomment the new comment
 * @param newposx the new X coordinate in the page
 * @param newposy the new Y coordinate in the page
 * @param newbonus the new bonus
 */
public void update(final String newcomment, int newposx, int newposy, final int newlevel, final float newbonus,
        final String newregrademarkercomment, final int newregradeaccepted, int widthPage, int heightPage) {

    final Mark mark = this;

    int regradeid = 0;
    if (mark instanceof RubricMark)
        regradeid = ((RubricMark) mark).getRegradeid();

    // This shouldn't happen so log it for debugging
    if (this.id == 0) {
        logger.severe("Fatal error! A comment with id 0!");
        return;
    }

    EMarkingWeb.markingInterface.addLoading(true);

    this.setLoading();

    final String feedbackToAjax;
    if (feedback.size() > 0) {
        feedbackToAjax = getFeedbackToAjax();
    } else {
        feedbackToAjax = "";
    }
    logger.severe(feedbackToAjax);
    // Call the ajax request to update the data
    AjaxRequest.ajaxRequest("action=updcomment&cid=" + this.id + "&posx=" + newposx + "&posy=" + newposy
            + "&bonus=" + newbonus + "&format=" + this.format + "&levelid=" + newlevel + "&regradeid="
            + regradeid + "&regradeaccepted=" + newregradeaccepted + "&regrademarkercomment="
            + newregrademarkercomment + "&markerid=" + EMarkingConfiguration.getMarkerId() + "&width="
            + this.width + "&height=" + this.height + "&comment=" + URL.encode(newcomment) + "&windowswidth="
            + widthPage + "&windowsheight=" + heightPage + "&feedback=" + URL.encode(feedbackToAjax),
            new AsyncCallback<AjaxData>() {

                @Override
                public void onFailure(Throwable caught) {
                    logger.severe("Error updating mark to Moodle!");
                    logger.severe(caught.getMessage());
                    Window.alert(caught.getMessage());
                    EMarkingWeb.markingInterface.finishLoading();
                }

                @Override
                public void onSuccess(AjaxData result) {
                    Map<String, String> value = AjaxRequest.getValueFromResult(result);

                    if (!result.getError().equals("")) {
                        Window.alert(result.getError());
                        setMarkHTML();
                        removeStyleName(Resources.INSTANCE.css().updating());
                        EMarkingWeb.markingInterface.finishLoading();
                        return;
                    }

                    // Parse json values from Moodle
                    long timemodified = Long.parseLong(value.get("timemodified"));
                    float newgrade = Float.parseFloat(value.get("newgrade"));
                    mark.setPreviousText(mark.getRawtext());
                    mark.setRawtext(newcomment);

                    if (mark instanceof RubricMark) {
                        RubricMark rmark = (RubricMark) mark;
                        // Update submission data
                        int previousLevelid = rmark.getLevelId();
                        float previousBonus = rmark.getBonus();
                        rmark.setLevelId(newlevel);
                        rmark.setBonus(newbonus);
                        rmark.setRegradeaccepted(newregradeaccepted);
                        rmark.setRegrademarkercomment(newregrademarkercomment);
                        if (rmark.getLevelId() != previousLevelid || rmark.getBonus() != previousBonus) {
                            rmark.setMarkername(MarkingInterface.submissionData.getMarkerfirstname() + " "
                                    + MarkingInterface.submissionData.getMarkerlastname());
                            rmark.setMarkerid(MarkingInterface.submissionData.getMarkerid());
                            Mark.showIcons(rmark, 0);
                        }
                        EMarkingWeb.markingInterface.getRubricInterface().getRubricPanel()
                                .addMarkToRubric(rmark);
                        EMarkingWeb.markingInterface.getRubricInterface().getRubricPanel()
                                .finishloadingRubricCriterion(newlevel);
                    }

                    // Update the marking interface with the final grade and time
                    EMarkingWeb.markingInterface.setFinalgrade(newgrade, timemodified);
                    setMarkHTML();

                    EMarkingWeb.markingInterface.getRubricInterface().getToolsPanel().getPreviousComments()
                            .addMarkAsCommentToInterface(mark, true);

                    removeStyleName(Resources.INSTANCE.css().updating());

                    EMarkingWeb.markingInterface.finishLoading();
                }
            });
}