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

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

Introduction

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

Prototype

@Deprecated
public static String decodeComponent(String encodedURLComponent) 

Source Link

Document

Returns a string where all URL component escape sequences have been converted back to their original character representations.

Usage

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

License:Apache License

/**
 * Creates a widget to render the gadget.
 *///from   w ww .  j  a  v  a2  s .c om
public void createWidget() {
    if (isActive()) {
        log("Repeated attempt to create gadget widget.");
        return;
    }

    active = true;
    log("Creating Gadget Widget ", getGadgetName());

    ui.enableMenu();
    allowModificationOfNewlyCreatedGadget();
    setSavedIframeHeight();
    setSavedIframeWidth();

    source = getAttribute(URL_ATTRIBUTE);
    String title = getAttribute(TITLE_ATTRIBUTE);
    ui.setTitleLabelText((title == null) ? "" : URL.decodeComponent(title));
    updatePrefsFromAttribute(getAttribute(PREFS_ATTRIBUTE));
    refreshParticipantInformation();

    // HACK(anorth): This event routing should happen outside the widget.
    ObservableConversation conv = (ObservableConversation) blip.getConversation();
    conv.addListener(new WaveletListenerAdapter(blip, this));
    log("Requesting Gadget metadata: ", source);
    String cachedIframeUrl = getAttribute(IFRAME_URL_ATTRIBUTE);
    if (validIframeUrl(cachedIframeUrl)) {
        registerWithController(cleanUrl(cachedIframeUrl), 0, 0);
    }
    GadgetDataStoreImpl.getInstance().getGadgetData(source, waveletName, getInstanceId(),
            new GadgetDataStore.DataCallback() {
                @Override
                public void onError(String message, Throwable t) {
                    if ((t != null) && (t.getMessage() != null)) {
                        message += " " + t.getMessage();
                    }
                    showBrokenGadget(message);
                }

                @Override
                public void onDataReady(GadgetMetadata metadata, String securityToken) {
                    if (isActive()) {
                        ReadableStringSet views = metadata.getViewSet();
                        String view = null;
                        if (views.contains(GADGET_PRIMARY_VIEW)) {
                            view = GADGET_PRIMARY_VIEW;
                        } else if (views.contains(GADGET_DEFAULT_VIEW)) {
                            view = GADGET_DEFAULT_VIEW;
                        } else if (!views.isEmpty()) {
                            view = views.someElement();
                        } else {
                            showBrokenGadget("Gadget has no view to render.");
                            return;
                        }
                        String url = metadata.getIframeUrl(view);
                        if (validIframeUrl(url)) {
                            constructGadgetFromMetadata(metadata, view, securityToken);
                        } else {
                            showBrokenGadget("Invalid IFrame URL " + url);
                        }
                    }
                }
            });
}

From source file:org.waveprotocol.wave.client.util.UrlParameters.java

License:Apache License

UrlParameters(String query) {
    if (query.length() > 1) {
        String[] keyvalpairs = query.substring(1, query.length()).split("&");
        for (String pair : keyvalpairs) {
            String[] keyval = pair.split("=");
            // Some basic error handling for invalid query params.
            if (keyval.length == 2) {
                map.put(URL.decodeComponent(keyval[0]), URL.decodeComponent(keyval[1]));
            } else if (keyval.length == 1) {
                map.put(URL.decodeComponent(keyval[0]), "");
            }/*  w  ww.j  ava  2 s .c  o m*/
        }
    }
}

From source file:org.waveprotocol.wave.examples.client.webclient.util.URLEncoderDecoderBasedPercentEncoderDecoder.java

License:Apache License

@Override
public String decode(String encodedValue) throws URIEncoderDecoder.EncodingException {
    // The URL decoder will replace + with space so percent escape it.
    encodedValue = encodedValue.replace("+", "%2B");

    String ret = URL.decodeComponent(encodedValue);
    if (ret.indexOf(0xFFFD) != -1) {
        throw new URIEncoderDecoder.EncodingException(
                "Unable to decode value " + encodedValue + " it contains invalid UTF-8");
    }/*from www.  jav a  2 s.c  o  m*/
    return ret;

}

From source file:tsd.client.QueryString.java

License:Open Source License

/**
 * Returns the decoded key-value parameter pairs of the URI.
 *//* w w  w.  j  a  v  a 2  s.  c om*/
public static QueryString decode(final String s) {
    final QueryString params = new QueryString();
    String name = null;
    int pos = 0; // Beginning of the unprocessed region
    int i; // End of the unprocessed region
    for (i = 0; i < s.length(); i++) {
        final char c = s.charAt(i);
        if (c == '=' && name == null) {
            if (pos != i) {
                name = URL.decodeComponent(s.substring(pos, i));
            }
            pos = i + 1;
        } else if (c == '&') {
            if (name == null && pos != i) {
                // We haven't seen an `=' so far but moved forward.
                // Must be a param of the form '&a&' so add it with
                // an empty value.
                params.add(URL.decodeComponent(s.substring(pos, i)), "");
            } else if (name != null) {
                params.add(name, URL.decodeComponent(s.substring(pos, i)));
                name = null;
            }
            pos = i + 1;
        }
    }

    if (pos != i) { // Are there characters we haven't dealt with?
        if (name == null) { // Yes and we haven't seen any `='.
            params.add(URL.decodeComponent(s.substring(pos, i)), "");
        } else { // Yes and this must be the last value.
            params.add(name, URL.decodeComponent(s.substring(pos, i)));
        }
    } else if (name != null) { // Have we seen a name without value?
        params.add(name, "");
    }

    return params;
}

From source file:viewer.QueryStringDecoder.java

License:Open Source License

/**
 * Returns the decoded key-value parameter pairs of the URI.
 */// ww  w .  ja  va2 s . c o  m
public static Map<String, List<String>> getParameters(final String s) {
    final Map<String, List<String>> params = new HashMap<String, List<String>>();
    String name = null;
    int pos = 0; // Beginning of the unprocessed region
    int i; // End of the unprocessed region
    char c = 0; // Current character
    for (i = 0; i < s.length(); i++) {
        c = s.charAt(i);
        if (c == '=' && name == null) {
            if (pos != i) {
                name = URL.decodeComponent(s.substring(pos, i));
            }
            pos = i + 1;
        } else if (c == '&') {
            if (name == null && pos != i) {
                // We haven't seen an `=' so far but moved forward.
                // Must be a param of the form '&a&' so add it with
                // an empty value.
                addParam(params, URL.decodeComponent(s.substring(pos, i)), "");
            } else if (name != null) {
                addParam(params, name, URL.decodeComponent(s.substring(pos, i)));
                name = null;
            }
            pos = i + 1;
        }
    }

    if (pos != i) { // Are there characters we haven't dealt with?
        if (name == null) { // Yes and we haven't seen any `='.
            addParam(params, URL.decodeComponent(s.substring(pos, i)), "");
        } else { // Yes and this must be the last value.
            addParam(params, name, URL.decodeComponent(s.substring(pos, i)));
        }
    } else if (name != null) { // Have we seen a name without value?
        addParam(params, name, "");
    }

    return params;
}