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:org.freemedsoftware.gwt.client.widget.PatientTagsWidget.java

License:Open Source License

/**
 * Update database to remove tag.//  w ww.j  a  v  a  2 s.  c  om
 * 
 * @param tag
 */
public void removeTag(String tag, final HorizontalPanel hp) {
    if (Util.getProgramMode() == ProgramMode.STUBBED) {
        hp.removeFromParent();
    } else if (Util.getProgramMode() == ProgramMode.JSONRPC) {
        String[] params = { JsonUtil.jsonify(patientId), tag };
        RequestBuilder builder = new RequestBuilder(RequestBuilder.POST,
                URL.encode(Util.getJsonRequest("org.freemedsoftware.module.PatientTag.ExpireTag", params)));
        try {
            builder.sendRequest(null, new RequestCallback() {
                public void onError(Request request, Throwable ex) {
                    Util.showErrorMsg("PatientTags", _("Failed to remove tag."));
                }

                public void onResponseReceived(Request request, Response response) {
                    if (200 == response.getStatusCode()) {
                        Boolean r = (Boolean) JsonUtil.shoehornJson(JSONParser.parseStrict(response.getText()),
                                "Boolean");
                        if (r != null) {
                            hp.removeFromParent();
                            Util.showInfoMsg("PatientTags", _("Tag removed."));
                        }
                    } else {
                        Util.showErrorMsg("PatientTags", _("Failed to remove tag."));
                    }
                }
            });
        } catch (RequestException e) {
            Util.showErrorMsg("PatientTags", _("Failed to remove tag."));
        }
    } else {
        getProxy().ExpireTag(patientId, tag, new AsyncCallback<Boolean>() {
            public void onSuccess(Boolean o) {
                hp.removeFromParent();
                Util.showErrorMsg("PatientTags", _("Tag removed."));
            }

            public void onFailure(Throwable t) {
                GWT.log("Exception", t);
                Util.showErrorMsg("PatientTags", _("Failed to remove tag."));
            }
        });
    }
}

From source file:org.freemedsoftware.gwt.client.widget.PatientTagsWidget.java

License:Open Source License

/**
 * Populate the widget via RPC.//from  w w w  . j av  a 2  s  .  c o m
 */
protected void populate() {
    if (Util.getProgramMode() == ProgramMode.STUBBED) {
        addTagToDisplay("testTag1");
        addTagToDisplay("Diabetes");
        addTagToDisplay("LatePayment");
    } else if (Util.getProgramMode() == ProgramMode.JSONRPC) {
        String[] params = { JsonUtil.jsonify(patientId) };
        RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, URL
                .encode(Util.getJsonRequest("org.freemedsoftware.module.PatientTag.TagsForPatient", params)));
        try {
            builder.sendRequest(null, new RequestCallback() {
                public void onError(Request request, Throwable ex) {
                }

                public void onResponseReceived(Request request, Response response) {
                    if (200 == response.getStatusCode()) {
                        JsonUtil.debug(response.getText());
                        String[] r = (String[]) JsonUtil
                                .shoehornJson(JSONParser.parseStrict(response.getText()), "String[]");
                        if (r != null) {
                            for (int iter = 0; iter < r.length; iter++) {
                                addTagToDisplay(r[iter]);
                            }
                        }
                    } else {
                    }
                }
            });
        } catch (RequestException e) {
        }
    } else {
        getProxy().TagsForPatient(patientId, new AsyncCallback<String[]>() {
            public void onSuccess(String[] tags) {
                for (int iter = 0; iter < tags.length; iter++) {
                    addTagToDisplay(tags[iter]);
                }
            }

            public void onFailure(Throwable t) {
                GWT.log("Exception", t);
            }
        });
    }
}

From source file:org.freemedsoftware.gwt.client.widget.PatientTagWidget.java

License:Open Source License

protected void loadSuggestions(String req, final Request r, final Callback cb) {
    if (Util.getProgramMode() == ProgramMode.STUBBED) {
        // Handle in a stubbed sort of way
        List<SuggestOracle.Suggestion> items = new ArrayList<SuggestOracle.Suggestion>();
        map.clear();//from ww  w . j  ava  2  s  . c o  m
        addKeyValuePair(items, new String("Diabetes"), new String("Diabetes"));
        addKeyValuePair(items, new String("Neuropathy"), new String("Neuropathy"));
        cb.onSuggestionsReady(r, new SuggestOracle.Response(items));
    } else if (Util.getProgramMode() == ProgramMode.JSONRPC) {
        String[] params = { req };
        RequestBuilder builder = new RequestBuilder(RequestBuilder.POST,
                URL.encode(Util.getJsonRequest("org.freemedsoftware.module.PatientTag.ListTags", params)));
        try {
            builder.sendRequest(null, new RequestCallback() {
                public void onError(com.google.gwt.http.client.Request request, Throwable ex) {
                }

                @SuppressWarnings("unchecked")
                public void onResponseReceived(com.google.gwt.http.client.Request request,
                        com.google.gwt.http.client.Response response) {
                    if (Util.checkValidSessionResponse(response.getText())) {
                        if (200 == response.getStatusCode()) {
                            HashMap<String, String> result = (HashMap<String, String>) JsonUtil.shoehornJson(
                                    JSONParser.parseStrict(response.getText()), "HashMap<String,String>");
                            if (result != null) {
                                List<SuggestOracle.Suggestion> items = new ArrayList<SuggestOracle.Suggestion>();
                                map.clear();
                                Iterator<String> iter = result.values().iterator();
                                while (iter.hasNext()) {
                                    String x = iter.next();
                                    addKeyValuePair(items, x, x);
                                }
                                cb.onSuggestionsReady(r, new SuggestOracle.Response(items));
                            }
                        } else {
                            GWT.log("Result " + response.getStatusText(), null);
                        }
                    }
                }
            });
        } catch (RequestException e) {
            GWT.log("Exception thrown: ", e);
        }
    } else {
        PatientTagAsync service = null;
        try {
            service = ((PatientTagAsync) Util.getProxy("org.freemedsoftware.gwt.client.Module.PatientTag"));
        } catch (Exception e) {
        }

        service.ListTags(req, new AsyncCallback<HashMap<String, String>>() {
            @Override
            public void onSuccess(HashMap<String, String> result) {
                List<SuggestOracle.Suggestion> items = new ArrayList<SuggestOracle.Suggestion>();
                map.clear();
                Iterator<String> iter = result.values().iterator();
                while (iter.hasNext()) {
                    String x = iter.next();
                    addKeyValuePair(items, x, x);
                }
                cb.onSuggestionsReady(r, new SuggestOracle.Response(items));
            }

            public void onFailure(Throwable t) {
                GWT.log("Exception thrown: ", t);
                Util.showErrorMsg("PatientTagWidget", "Exception: " + t.toString());
            }

        });
    }
}

From source file:org.freemedsoftware.gwt.client.widget.PatientWidget.java

License:Open Source License

protected void loadSuggestions(String req, final Request r, final Callback cb) {
    if (req.length() < CurrentState.getMinCharCountForSmartSearch())
        return;/* w w  w .  jav a 2s.  c  om*/
    if (Util.getProgramMode() == ProgramMode.STUBBED) {
        // Handle in a stubbed sort of way
        List<SuggestOracle.Suggestion> items = new ArrayList<SuggestOracle.Suggestion>();
        map.clear();
        addKeyValuePair(items, new String("Hackenbush, Hugo Z"), new String("1"));
        addKeyValuePair(items, new String("Firefly, Rufus T"), new String("2"));
        cb.onSuggestionsReady(r, new SuggestOracle.Response(items));
    } else if (Util.getProgramMode() == ProgramMode.JSONRPC) {
        String[] params = { req, new Integer(20).toString() };
        RequestBuilder builder = new RequestBuilder(RequestBuilder.POST,
                URL.encode(Util.getJsonRequest("org.freemedsoftware.api.PatientInterface.Picklist", params)));
        try {
            builder.sendRequest(null, new RequestCallback() {
                public void onError(com.google.gwt.http.client.Request request, Throwable ex) {
                    Window.alert(ex.toString());
                }

                @SuppressWarnings("unchecked")
                public void onResponseReceived(com.google.gwt.http.client.Request request,
                        com.google.gwt.http.client.Response response) {
                    if (200 == response.getStatusCode()) {
                        if (Util.checkValidSessionResponse(response.getText())) {
                            HashMap<Integer, String> result = (HashMap<Integer, String>) JsonUtil.shoehornJson(
                                    JSONParser.parseStrict(response.getText()), "HashMap<Integer,String>");
                            if (result != null) {
                                Set<Integer> keys = result.keySet();
                                Iterator<Integer> iter = keys.iterator();

                                List<SuggestOracle.Suggestion> items = new ArrayList<SuggestOracle.Suggestion>();
                                map.clear();
                                while (iter.hasNext()) {
                                    Integer keyInt = (Integer) iter.next();
                                    String key = keyInt.toString();
                                    String val = (String) result.get(keyInt);
                                    addKeyValuePair(items, val, key);
                                }
                                cb.onSuggestionsReady(r, new SuggestOracle.Response(items));
                            }
                        }
                    } else {
                        Window.alert(response.toString());
                    }
                }
            });
        } catch (RequestException e) {
            Window.alert(e.toString());
        }
    } else {
        PatientInterfaceAsync service = null;
        try {
            service = ((PatientInterfaceAsync) Util
                    .getProxy("org.freemedsoftware.gwt.client.Api.PatientInterface"));
        } catch (Exception e) {
        }

        service.Picklist(req, new Integer(20), new AsyncCallback<HashMap<Integer, String>>() {
            public void onSuccess(HashMap<Integer, String> result) {
                Set<Integer> keys = result.keySet();
                Iterator<Integer> iter = keys.iterator();

                List<SuggestOracle.Suggestion> items = new ArrayList<SuggestOracle.Suggestion>();
                map.clear();
                while (iter.hasNext()) {
                    Integer keyInt = (Integer) iter.next();
                    String key = keyInt.toString();
                    // Log.debug("keyInt = " + keyInt.toString());
                    String val = (String) result.get(keyInt);
                    addKeyValuePair(items, val, key);
                }
                cb.onSuggestionsReady(r, new SuggestOracle.Response(items));
            }

            public void onFailure(Throwable t) {
                Window.alert(t.getMessage());
            }

        });
    }
}

From source file:org.freemedsoftware.gwt.client.widget.PatientWidget.java

License:Open Source License

@Override
public void getTextForValue(Integer val) {
    if (val > 0) {
        if (Util.getProgramMode() == ProgramMode.STUBBED) {
            searchBox.setText("Hackenbush, Hugo Z (STUB)");
        } else if (Util.getProgramMode() == ProgramMode.JSONRPC) {
            textBox.setEnabled(false);//from  w ww. j a va 2  s.  c om
            String[] params = { val.toString() };
            RequestBuilder builder = new RequestBuilder(RequestBuilder.POST,
                    URL.encode(Util.getJsonRequest("org.freemedsoftware.api.PatientInterface.ToText", params)));
            try {
                builder.sendRequest(null, new RequestCallback() {
                    public void onError(com.google.gwt.http.client.Request request, Throwable ex) {
                        textBox.setEnabled(true);
                        Window.alert(ex.toString());
                    }

                    public void onResponseReceived(com.google.gwt.http.client.Request request,
                            com.google.gwt.http.client.Response response) {
                        textBox.setEnabled(true);
                        if (Util.checkValidSessionResponse(response.getText())) {
                            if (200 == response.getStatusCode()) {
                                String result = (String) JsonUtil
                                        .shoehornJson(JSONParser.parseStrict(response.getText()), "String");
                                if (result != null) {
                                    searchBox.setText(result);
                                    if (callback != null) {
                                        callback.jsonifiedData("done");
                                    }
                                }
                            } else {
                                Window.alert(response.toString());
                            }
                        }
                    }
                });
            } catch (RequestException e) {
                textBox.setEnabled(true);
                Window.alert(e.toString());
            }
        } else {
            PatientInterfaceAsync service = null;
            try {
                service = ((PatientInterfaceAsync) Util
                        .getProxy("org.freemedsoftware.gwt.client.Api.PatientInterface"));
            } catch (Exception e) {
            }
            textBox.setEnabled(false);
            service.ToText(val, true, new AsyncCallback<String>() {
                public void onSuccess(String r) {
                    textBox.setEnabled(true);
                    searchBox.setText(r);
                }

                public void onFailure(Throwable t) {
                    textBox.setEnabled(true);
                    GWT.log("Exception", t);
                }
            });
        }
    }
}

From source file:org.freemedsoftware.gwt.client.widget.PharmacyWidget.java

License:Open Source License

protected void loadSuggestions(String req, final Request r, final Callback cb) {
    if (Util.getProgramMode() == ProgramMode.STUBBED) {
        // Handle in a stubbed sort of way
        List<SuggestOracle.Suggestion> items = new ArrayList<SuggestOracle.Suggestion>();
        map.clear();/*  w  w  w .j a  va  2  s . c  o  m*/
        addKeyValuePair(items, new String("Cranston GOP (Cranston, RI)"), new String("1"));
        cb.onSuggestionsReady(r, new SuggestOracle.Response(items));
    } else if (Util.getProgramMode() == ProgramMode.JSONRPC) {
        String[] params = { req, new Integer(20).toString() };
        RequestBuilder builder = new RequestBuilder(RequestBuilder.POST,
                URL.encode(Util.getJsonRequest("org.freemedsoftware.module.Pharmacy.Picklist", params)));
        try {
            builder.sendRequest(null, new RequestCallback() {
                public void onError(com.google.gwt.http.client.Request request, Throwable ex) {
                    Window.alert(ex.toString());
                }

                @SuppressWarnings("unchecked")
                public void onResponseReceived(com.google.gwt.http.client.Request request,
                        com.google.gwt.http.client.Response response) {
                    if (200 == response.getStatusCode()) {
                        if (Util.checkValidSessionResponse(response.getText())) {
                            HashMap<Integer, String> result = (HashMap<Integer, String>) JsonUtil.shoehornJson(
                                    JSONParser.parseStrict(response.getText()), "HashMap<Integer,String>");
                            if (result != null) {
                                Set<Integer> keys = result.keySet();
                                Iterator<Integer> iter = keys.iterator();

                                List<SuggestOracle.Suggestion> items = new ArrayList<SuggestOracle.Suggestion>();
                                map.clear();
                                while (iter.hasNext()) {
                                    Integer keyInt = (Integer) iter.next();
                                    String key = keyInt.toString();
                                    String val = (String) result.get(keyInt);
                                    addKeyValuePair(items, val, key);
                                }
                                cb.onSuggestionsReady(r, new SuggestOracle.Response(items));
                            }
                        }
                    } else {
                        Window.alert(response.toString());
                    }
                }
            });
        } catch (RequestException e) {
            Window.alert(e.toString());
        }
    } else {

        // TODO GWT CODE GOES HERE

    }
}

From source file:org.freemedsoftware.gwt.client.widget.PharmacyWidget.java

License:Open Source License

@Override
public void getTextForValue(Integer val) {
    if (val > 0) {
        if (Util.getProgramMode() == ProgramMode.STUBBED) {
            searchBox.setText("Cranston GOP (Cranston, RI)(STUB)");
        } else if (Util.getProgramMode() == ProgramMode.JSONRPC) {
            textBox.setEnabled(false);// www  .  j  a  v a 2  s. c o m
            String[] params = { val.toString() };
            RequestBuilder builder = new RequestBuilder(RequestBuilder.POST,
                    URL.encode(Util.getJsonRequest("org.freemedsoftware.module.Pharmacy.To_Text", params)));
            try {
                builder.sendRequest(null, new RequestCallback() {
                    public void onError(com.google.gwt.http.client.Request request, Throwable ex) {
                        textBox.setEnabled(true);
                        Window.alert(ex.toString());
                    }

                    public void onResponseReceived(com.google.gwt.http.client.Request request,
                            com.google.gwt.http.client.Response response) {
                        textBox.setEnabled(true);
                        if (Util.checkValidSessionResponse(response.getText())) {
                            if (200 == response.getStatusCode()) {
                                String result = (String) JsonUtil
                                        .shoehornJson(JSONParser.parseStrict(response.getText()), "String");
                                if (result != null) {
                                    searchBox.setText(result);
                                }
                            } else {
                                Window.alert(response.toString());
                            }
                        }
                    }
                });
            } catch (RequestException e) {
                textBox.setEnabled(true);
                Window.alert(e.toString());
            }
        } else {
            // TODO GWT STUFF
        }
    }
}

From source file:org.freemedsoftware.gwt.client.widget.PostCheckWidget.java

License:Open Source License

public void loadSelectedProcedureInfo() {
    if (Util.getProgramMode() == ProgramMode.STUBBED) {

    } else if (Util.getProgramMode() == ProgramMode.JSONRPC) {
        String[] params = { procs.toString() };
        RequestBuilder builder = new RequestBuilder(RequestBuilder.POST,
                URL.encode(Util.getJsonRequest("org.freemedsoftware.api.ClaimLog.getProceduresInfo", params)));
        try {/*from  w w w .ja  v a  2 s. c  o m*/
            builder.sendRequest(null, new RequestCallback() {
                public void onError(Request request, Throwable ex) {
                    Window.alert(ex.toString());
                }

                @SuppressWarnings("unchecked")
                public void onResponseReceived(Request request, Response response) {

                    if (Util.checkValidSessionResponse(response.getText())) {
                        if (200 == response.getStatusCode()) {
                            try {
                                HashMap<String, String>[] result = (HashMap<String, String>[]) JsonUtil
                                        .shoehornJson(JSONParser.parseStrict(response.getText()),
                                                "HashMap<String,String>[]");
                                if (result != null) {
                                    if (result.length > 0) {
                                        proceduresInfoTable.loadData(result);
                                    }
                                }
                            } catch (Exception e) {

                            }
                        } else {
                        }
                    }
                }
            });
        } catch (RequestException e) {
            Window.alert(e.toString());
        }

    } else {
    }
}

From source file:org.freemedsoftware.gwt.client.widget.PostCheckWidget.java

License:Open Source License

public void postCheck(HashMap<String, String>[] maps) {
    final PostCheckWidget pcw = this;
    if (Util.getProgramMode() == ProgramMode.STUBBED) {

    } else if (Util.getProgramMode() == ProgramMode.JSONRPC) {
        // String[] params = { "" + payerWidget.getStoredValue(),
        // JsonUtil.jsonify(tbCheckNo.getText()),
        // JsonUtil.jsonify(maps) };
        String[] params = { "", JsonUtil.jsonify(tbCheckNo.getText()), JsonUtil.jsonify(maps) };
        RequestBuilder builder = new RequestBuilder(RequestBuilder.POST,
                URL.encode(Util.getJsonRequest("org.freemedsoftware.api.ClaimLog.post_check", params)));
        try {//from  ww  w .  ja v  a2s.c o  m
            builder.sendRequest(null, new RequestCallback() {
                public void onError(Request request, Throwable ex) {
                    Window.alert(ex.toString());
                }

                public void onResponseReceived(Request request, Response response) {

                    if (Util.checkValidSessionResponse(response.getText())) {
                        if (200 == response.getStatusCode()) {
                            pcw.removeFromParent();
                            callback.jsonifiedData("update");
                        } else {
                        }
                    }
                }
            });
        } catch (RequestException e) {
            Window.alert(e.toString());
        }

    } else {
    }
}

From source file:org.freemedsoftware.gwt.client.widget.PrescriptionRefillBox.java

License:Open Source License

public void showStaff() {

    cleanView();//from   w ww.  j  a  va  2s  .  com

    flexTable.getFlexCellFormatter().setColSpan(1, 0, 1);

    final PatientWidget patientWidget = new PatientWidget();
    flexTable.setWidget(1, 1, patientWidget);

    final Label selectionLabel = new Label(_("Select a Patient") + ":");
    flexTable.setWidget(1, 0, selectionLabel);

    final Label textLabel = new Label(_("Add an optional note") + ":");
    flexTable.setWidget(2, 0, textLabel);

    final TextBox textBox = new TextBox();
    flexTable.setWidget(2, 1, textBox);
    textBox.setWidth("100%");

    final CustomButton sendButton = new CustomButton(_("Send Request"), AppConstants.ICON_SEND);
    flexTable.setWidget(3, 1, sendButton);

    sendButton.addClickHandler(new ClickHandler() {
        @Override
        public void onClick(ClickEvent evt) {
            String msg = "";
            if (Integer.parseInt(patientWidget.getStoredValue()) == 0)
                msg = _("Please select a patient.");
            if (textBox.getText().trim().length() == 0)
                msg += "\n" + _("Please add a short note.");

            if (msg.length() > 0) {
                Util.showErrorMsg(moduleName, msg);
                return;
            }

            patid = patientWidget.value;

            HashMap<String, String> data = new HashMap<String, String>();
            // data.put("id", "some stuff"); not needed??
            data.put("provider", Integer.toString(CurrentState.getDefaultProvider()));
            data.put("note", textBox.getText());
            data.put("patient", Integer.toString(patid));
            // send stuff
            if (Util.getProgramMode() == ProgramMode.STUBBED) {
                // do nothing - we just save the stuff
            } else if (Util.getProgramMode() == ProgramMode.JSONRPC) {
                String[] params = { JsonUtil.jsonify(data) };
                RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, URL
                        .encode(Util.getJsonRequest("org.freemedsoftware.module.RxRefillRequest.add", params)));
                try {
                    builder.sendRequest(null, new RequestCallback() {
                        public void onError(Request request, Throwable ex) {
                            Util.showErrorMsg("PrescriptionRefillBox",
                                    _("Error adding refill request.") + ex.toString());
                        }

                        public void onResponseReceived(Request request, Response response) {
                            if (200 == response.getStatusCode()) {
                                Integer r = (Integer) JsonUtil
                                        .shoehornJson(JSONParser.parseStrict(response.getText()), "Integer");
                                if (r != 0) {
                                    Util.showInfoMsg("PrescriptionRefillBox",
                                            _("Refill request successfully saved."));
                                }
                            } else {
                                Util.showErrorMsg("PrescriptionRefillBox",
                                        _("Error adding prescription refill request."));
                            }
                        }
                    });
                } catch (RequestException e) {
                }

            } else if (Util.getProgramMode() == ProgramMode.NORMAL) {
                // TODO: GWT-RPC still missing
            }

        }

    });
}