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

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

Introduction

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

Prototype

public static String encodeQueryString(String decodedURLComponent) 

Source Link

Document

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

Usage

From source file:org.unitime.timetable.gwt.client.rooms.RoomFeaturesPage.java

License:Apache License

protected String query(String format) {
    RoomCookie cookie = RoomCookie.getInstance();
    String query = "output=" + format + "&sort=" + cookie.getRoomsSortBy()
            + (cookie.hasMode() ? "&mode=" + cookie.getMode() : "") + "&dm=" + cookie.getDeptMode();
    if (iProperties.getAcademicSessionId() != null)
        query += "&sid=" + iProperties.getAcademicSessionId();

    FilterRpcRequest rooms = iFilter.getElementsRequest();
    if (rooms.hasOptions()) {
        for (Map.Entry<String, Set<String>> option : rooms.getOptions().entrySet()) {
            for (String value : option.getValue()) {
                query += "&r:" + option.getKey() + "=" + URL.encodeQueryString(value);
            }/*w  w w.ja va2 s  . c o  m*/
        }
    }

    if (rooms.getText() != null && !rooms.getText().isEmpty())
        query += "&r:text=" + URL.encodeQueryString(rooms.getText());

    return query;
}

From source file:org.unitime.timetable.gwt.client.rooms.RoomsPage.java

License:Apache License

protected String query(String format) {
    RoomCookie cookie = RoomCookie.getInstance();
    int flags = (iRoomsTable == null ? cookie.getFlags(iMode)
            : cookie.getFlags(iMode) & iRoomsTable.getFlags());
    String query = "output=" + format + "&flags=" + flags + "&sort=" + cookie.getRoomsSortBy() + "&orientation="
            + (cookie.isGridAsText() ? "text" : cookie.areRoomsHorizontal() ? "horizontal" : "vertical")
            + (cookie.hasMode() ? "&mode=" + cookie.getMode() : "") + "&dm=" + cookie.getDeptMode();
    if (iProperties.getAcademicSessionId() != null)
        query += "&sid=" + iProperties.getAcademicSessionId();

    FilterRpcRequest rooms = iFilter.getElementsRequest();
    if (rooms.hasOptions()) {
        for (Map.Entry<String, Set<String>> option : rooms.getOptions().entrySet()) {
            for (String value : option.getValue()) {
                query += "&r:" + option.getKey() + "=" + URL.encodeQueryString(value);
            }// www.  ja v a 2  s . c om
        }
    }

    if (rooms.getText() != null && !rooms.getText().isEmpty())
        query += "&r:text=" + URL.encodeQueryString(rooms.getText());

    return query;
}

From source file:org.unitime.timetable.gwt.client.sectioning.StudentSectioningPage.java

License:Apache License

public StudentSectioningPage(final Mode mode) {
    final UserAuthentication userAuthentication = new UserAuthentication(
            UniTimePageHeader.getInstance().getMiddle(),
            mode.isSectioning() ? !CONSTANTS.isAuthenticationRequired() : false);

    if (Window.Location.getParameter("student") == null)
        iSectioningService.whoAmI(new AsyncCallback<String>() {
            public void onFailure(Throwable caught) {
                if (!mode.isSectioning() || CONSTANTS.isAuthenticationRequired()
                        || CONSTANTS.tryAuthenticationWhenGuest()) {
                    if (CONSTANTS.allowUserLogin())
                        userAuthentication.authenticate();
                    else if (!mode.isSectioning() || CONSTANTS.isAuthenticationRequired())
                        ToolBox.open(GWT.getHostPageBaseURL() + "login.do?target="
                                + URL.encodeQueryString(Window.Location.getHref()));
                    else
                        userAuthentication.authenticated(null);
                }//from   ww  w  .java  2 s .  c  o  m
            }

            public void onSuccess(String result) {
                if (result == null) { // not authenticated
                    if (!mode.isSectioning() || CONSTANTS.isAuthenticationRequired()
                            || CONSTANTS.tryAuthenticationWhenGuest()) {
                        if (CONSTANTS.allowUserLogin())
                            userAuthentication.authenticate();
                        else if (!mode.isSectioning() || CONSTANTS.isAuthenticationRequired())
                            ToolBox.open(GWT.getHostPageBaseURL() + "login.do?target="
                                    + URL.encodeQueryString(Window.Location.getHref()));
                        else
                            userAuthentication.authenticated(result);
                    } else {
                        userAuthentication.authenticated(result);
                    }
                } else {
                    userAuthentication.authenticated(result);
                }
            }
        });

    final AcademicSessionSelector sessionSelector = new AcademicSessionSelector(
            UniTimePageHeader.getInstance().getRight(), mode);

    iSectioningService.getProperties(null, new AsyncCallback<SectioningProperties>() {
        public void onFailure(Throwable caught) {
        }

        public void onSuccess(SectioningProperties result) {
            if (result.isAdmin()) {
                userAuthentication.setAllowLookup(true);
                if (Window.Location.getParameter("session") != null)
                    sessionSelector.selectSession(Long.valueOf(Window.Location.getParameter("session")),
                            new AsyncCallback<Boolean>() {
                                @Override
                                public void onFailure(Throwable caught) {
                                }

                                @Override
                                public void onSuccess(Boolean result) {
                                    if (Window.Location.getParameter("student") != null)
                                        UserAuthentication.personFound(Window.Location.getParameter("student"));
                                }
                            });
            } else {
                userAuthentication.setAllowLookup(false);
            }
        }
    });

    UniTimePageHeader.getInstance().getLeft().setVisible(false);
    UniTimePageHeader.getInstance().getLeft().setPreventDefault(true);

    final StudentSectioningWidget widget = new StudentSectioningWidget(true, sessionSelector,
            userAuthentication, mode, true);

    initWidget(widget);

    UniTimePageHeader.getInstance().getRight().setClickHandler(new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            if (widget.isChanged()) {
                UniTimeConfirmationDialog.confirm(widget.useDefaultConfirmDialog(),
                        MESSAGES.queryLeaveChanges(), new Command() {
                            @Override
                            public void execute() {
                                sessionSelector.selectSession();
                            }
                        });
            } else {
                sessionSelector.selectSession();
            }
        }
    });
    UniTimePageHeader.getInstance().getMiddle().setClickHandler(new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            if (CONSTANTS.allowUserLogin()) {
                if (widget.isChanged()) {
                    UniTimeConfirmationDialog.confirm(widget.useDefaultConfirmDialog(),
                            MESSAGES.queryLeaveChanges(), new Command() {
                                @Override
                                public void execute() {
                                    if (userAuthentication.isLoggedIn())
                                        userAuthentication.logOut();
                                    else
                                        userAuthentication.authenticate();
                                }
                            });
                } else {
                    if (userAuthentication.isLoggedIn())
                        userAuthentication.logOut();
                    else
                        userAuthentication.authenticate();
                }
            } else if (userAuthentication.isAllowLookup()) {
                userAuthentication.doLookup();
            } else if (userAuthentication.isLoggedIn()) {
                ToolBox.open(GWT.getHostPageBaseURL() + "logOut.do");
            } else {
                ToolBox.open(GWT.getHostPageBaseURL() + "login.do?target="
                        + URL.encodeQueryString(Window.Location.getHref()));
            }
        }
    });

    userAuthentication.addUserAuthenticatedHandler(new UserAuthentication.UserAuthenticatedHandler() {
        public void onLogIn(UserAuthenticatedEvent event) {
            if (!mode.isSectioning())
                sessionSelector.selectSession(null, false);
            sessionSelector.selectSession();
        }

        public void onLogOut(UserAuthenticatedEvent event) {
            if (!event.isGuest()) {
                widget.clearMessage();
                widget.clear();
                // sessionSelector.selectSession(null);
            }
            userAuthentication.authenticate();
        }
    });

    sessionSelector.addAcademicSessionChangeHandler(new AcademicSessionProvider.AcademicSessionChangeHandler() {
        public void onAcademicSessionChange(AcademicSessionProvider.AcademicSessionChangeEvent event) {
            if (event.isChanged()) {
                widget.clearMessage();
                widget.clear();
            }
            widget.checkEligibility(event.getNewAcademicSessionId(), null, false, null);
            userAuthentication.setLookupOptions(
                    "mustHaveExternalId,source=students,session=" + event.getNewAcademicSessionId());
        }
    });

    if (Window.Location.getParameter("session") == null)
        iSectioningService.lastAcademicSession(mode.isSectioning(),
                new AsyncCallback<AcademicSessionProvider.AcademicSessionInfo>() {
                    public void onFailure(Throwable caught) {
                        if (!userAuthentication.isShowing() && !UniTimeFrameDialog.hasDialog())
                            sessionSelector.selectSession();
                    }

                    public void onSuccess(AcademicSessionProvider.AcademicSessionInfo result) {
                        sessionSelector.selectSession(result, true);
                    }
                });

    Window.addWindowClosingHandler(new Window.ClosingHandler() {
        @Override
        public void onWindowClosing(ClosingEvent event) {
            if (widget.isChanged()) {
                if (LoadingWidget.getInstance().isShowing())
                    LoadingWidget.getInstance().hide();
                event.setMessage(MESSAGES.queryLeaveChanges());
            }
        }
    });
}

From source file:org.unitime.timetable.gwt.client.sectioning.UserAuthentication.java

License:Apache License

public void authenticate() {
    if (!CONSTANTS.allowUserLogin()) {
        if (isAllowLookup())
            doLookup();//from  w ww .  j  a va 2s.com
        else
            ToolBox.open(GWT.getHostPageBaseURL() + "login.do?target="
                    + URL.encodeQueryString(Window.Location.getHref()));
        return;
    }
    AriaStatus.getInstance().setText(ARIA.authenticationDialogOpened());
    iError.setVisible(false);
    iDialog.center();
    Scheduler.get().scheduleDeferred(new ScheduledCommand() {
        @Override
        public void execute() {
            iUserName.selectAll();
            iUserName.setFocus(true);
        }
    });
}

From source file:org.unitime.timetable.gwt.client.solver.PageFilter.java

License:Apache License

public String getQuery() {
    String query = "";
    for (FilterParameterInterface param : iFilter.getParameters()) {
        String value = param.getValue();
        if (value != null)
            query += "&" + param.getName() + "=" + URL.encodeQueryString(value);
    }/*from   w  w w. j  av a 2  s  .  c  o m*/
    return query;
}

From source file:org.unitime.timetable.gwt.client.ToolBox.java

License:Apache License

public static void checkAccess(Throwable t) {
    if (t != null && t instanceof GwtRpcException && t.getCause() != null)
        t = t.getCause();//from w w w.j  av a2s  .  c om
    if (t != null && t instanceof PageAccessException) {
        open(GWT.getHostPageBaseURL() + "login.do?menu=hide&m=" + URL.encodeQueryString(t.getMessage())
                + "&target=" + URL.encodeQueryString(Window.Location.getHref()));
        /*
        UniTimeFrameDialog.openDialog("UniTime " + CONSTANTS.version() + "| Log In", "login.do?menu=hide&m=" + URL.encodeQueryString(t.getMessage())
              +"&target=" + URL.encodeQueryString(Window.Location.getHref()), "700px", "420px");
        */
    }
}

From source file:org.vaadin.addon.ewopener.client.EnhancedBrowserWindowOpenerConnector.java

License:Apache License

private String addParametersAndFragment(String url) {
    if (url == null) {
        return null;
    }/* ww w  . ja  va2 s  .c  om*/

    if (!getState().parameters.isEmpty()) {
        StringBuilder params = new StringBuilder();
        for (Map.Entry<String, String> entry : getState().parameters.entrySet()) {
            if (params.length() != 0) {
                params.append('&');
            }
            params.append(URL.encodeQueryString(entry.getKey()));
            params.append('=');

            String value = entry.getValue();
            if (value != null) {
                params.append(URL.encodeQueryString(value));
            }
        }

        url = SharedUtil.addGetParameters(url, params.toString());
    }

    if (getState().uriFragment != null) {
        // Replace previous fragment or just add to the end of the url
        url = url.replaceFirst("#.*|$", "#" + getState().uriFragment);
    }

    return url;
}

From source file:org.waveprotocol.box.webclient.flags.UrlParameters.java

License:Apache License

/**
 * Build a query string out of a map of key/value pairs.
 * @param queryEntries//  w  ww .jav a2 s.  c  o  m
 */
public static String buildQueryString(Map<String, String> queryEntries) {
    StringBuilder sb = new StringBuilder();
    boolean firstIteration = true;
    for (Entry<String, String> e : queryEntries.entrySet()) {
        if (firstIteration) {
            sb.append('?');
        } else {
            sb.append('&');
        }
        String encodedName = URL.encodeQueryString(e.getKey());
        sb.append(encodedName);

        sb.append('=');

        String encodedValue = URL.encodeQueryString(e.getValue());
        sb.append(encodedValue);
        firstIteration = false;
    }
    return sb.toString();
}

From source file:org.waveprotocol.box.webclient.folder.FolderOperationBuilderImpl.java

License:Apache License

@Override
public String getUrl() {
    StringBuilder sb = new StringBuilder();
    sb.append(FOLDER_OPERATION_URL_BASE);
    sb.append("/?");
    for (int i = 0; i < parameters.size(); i++) {
        if (i != 0) {
            sb.append("&");
        }// www .j a va 2  s .  c o m
        Parameter param = parameters.get(i);
        sb.append(param.name).append("=").append(URL.encodeQueryString(param.value));
    }
    return sb.toString();
}

From source file:org.waveprotocol.wave.client.gadget.renderer.GadgetWidget.java

License:Apache License

/**
 * Constructs IFrame URI of this gadget.
 *
 * @param instanceId instance to encode in the URI.
 * @param url URL template./*from ww  w  .j a v a2s.c  o  m*/
 * @return IFrame URI of this gadget.
 */
String buildIframeUrl(int instanceId, String url) {
    final StringBuilder builder = new StringBuilder();
    String fragment = "";
    int fragmentIndex = url.indexOf("#");
    if (fragmentIndex >= 0) {
        fragment = url.substring(fragmentIndex + 1);
        url = url.substring(0, fragmentIndex);
    }
    builder.append(url);

    boolean enableGadgetCache = false;

    builder.append("&nocache=" + (enableGadgetCache ? "0" : "1"));
    builder.append("&mid=" + instanceId);
    builder.append("&lang=" + locale.getLanguage());
    builder.append("&country=" + locale.getCountry());
    String href = getUrlPrefix();
    // TODO(user): Parent is normally the last non-hash parameter. It is moved
    // as a temp fix for kitchensinky. Move it back when the kitchensinky is
    // working wihout this workaround.
    builder.append("&parent=" + URL.encode(href));
    builder.append("&wave=" + WAVE_API_VERSION);
    builder.append("&waveId="
            + URL.encodeQueryString(ModernIdSerialiser.INSTANCE.serialiseWaveId(waveletName.waveId)));
    fragment = updateGadgetUriFragment(fragment);
    if (!fragment.isEmpty()) {
        builder.append("#" + fragment);
        log("Appended fragment: ", fragment);
    }
    if (userPrefs != null) {
        userPrefs.each(new StateMap.Each() {
            @Override
            public void apply(String key, String value) {
                if (value != null) {
                    builder.append("&up_");
                    builder.append(URL.encodeQueryString(key));
                    builder.append('=');
                    builder.append(URL.encodeQueryString(value));
                }
            }
        });
    }
    return builder.toString();
}