Example usage for com.google.gwt.safehtml.shared UriUtils isSafeUri

List of usage examples for com.google.gwt.safehtml.shared UriUtils isSafeUri

Introduction

In this page you can find the example usage for com.google.gwt.safehtml.shared UriUtils isSafeUri.

Prototype

public static boolean isSafeUri(String uri) 

Source Link

Document

Determines if a String is safe to use as the value of a URI-valued HTML attribute such as src or href .

Usage

From source file:cc.kune.common.shared.utils.TextUtils.java

License:GNU Affero Public License

/**
 * Generates a href link.// w ww.j a v a2 s  . co m
 *
 * @param href
 *          the href
 * @param text
 *          the text
 * @param targetBlank
 *          the target blank
 * @return the string
 */
public static String generateHtmlLink(final String href, final String text, final boolean targetBlank) {
    if (!UriUtils.isSafeUri(href)) {
        throw new UIException("Unsafe href");
    }
    return "<a href=\"" + UriUtils.sanitizeUri(href) + "\"" + (targetBlank ? "target=\"_blank\"" : "") + ">"
            + text + "</a>";
}

From source file:org.obiba.opal.web.gwt.app.client.ui.celltable.AttributeColumn.java

License:Open Source License

private void appendLabel(AttributeDto attr, StringBuilder labels) {
    if (attr.hasValue() && attr.getValue().trim().length() > 0) {
        labels.append("<div class=\"attribute-value\">");
        if (AttributeDtos.SCRIPT_ATTRIBUTE.equals(attr.getName())) {
            labels.append("<pre>");
        }/*from   w ww. jav  a 2  s  . c om*/
        if (attr.hasLocale() && attr.getLocale().trim().length() > 0) {
            labels.append("<span class=\"label\">").append(attr.getLocale()).append("</span> ");
        }
        String value = attr.getValue();
        String safeValue = SafeHtmlUtils.fromString(value).asString().replaceAll("\\n", "<br />");
        try {
            if (UriUtils.extractScheme(value) != null && UriUtils.isSafeUri(value)) {
                labels.append("<a href=").append(value).append(" target=\"_blank\">").append(safeValue)
                        .append("</a>");
            } else {
                labels.append(safeValue);
            }
        } catch (Exception e) {
            labels.append(safeValue);
        }
        if (AttributeDtos.SCRIPT_ATTRIBUTE.equals(attr.getName())) {
            labels.append("</pre>");
        }
        labels.append("</div>");
    }
}

From source file:org.obiba.opal.web.gwt.app.client.ui.celltable.LocaleTextColumn.java

License:Open Source License

private void appendLabel(LocaleTextDto attr, StringBuilder labels) {
    labels.append("<div class=\"attribute-value\">");
    if (attr.hasLocale() && attr.getLocale().trim().length() > 0) {
        labels.append("<span class=\"label\">").append(attr.getLocale()).append("</span> ");
    }//from w  w  w  .  j  a  v a  2s . c o m
    String value = attr.getText();
    String safeValue = SafeHtmlUtils.fromString(value).asString().replaceAll("\\n", "<br />");
    try {
        if (UriUtils.extractScheme(value) != null && UriUtils.isSafeUri(value)) {
            labels.append("<a href=").append(value).append(" target=\"_blank\">").append(safeValue)
                    .append("</a>");
        } else {
            labels.append(safeValue);
        }
    } catch (Exception e) {
        labels.append(safeValue);
    }
    labels.append("</div>");
}

From source file:org.primordion.xholon.service.SearchEngineService.java

License:Open Source License

@SuppressWarnings("unchecked")
public void doAction(String action) {
    //consoleLog("SES action:" + action);
    if (action == null) {
        return;/*  ww  w.jav a  2  s.  c  om*/
    }
    Map<String, String> map = (Map<String, String>) getFirstChild();
    if (map == null) {
        return;
    }
    boolean shouldBeLowerCase = false;
    boolean shouldBeCapitalized = false; // HelloWorld becomes Hello world
    boolean shouldBeListOf = false;
    boolean shouldHandleMultiSelection = false;
    StringTokenizer st = new StringTokenizer(action, ",");
    String searchEngineName = st.nextToken();
    String searchTermOriginal = st.nextToken();
    if (listOf != null && isPlural(searchTermOriginal)) {
        // we only check the nodeClassName, and not the roleName
        shouldBeListOf = true;
    }
    if (st.hasMoreTokens() && preferRoleName) {
        searchTermOriginal = st.nextToken();
    }
    String searchTerm = searchTermOriginal;
    String replaceStr = "+"; // replace camel case with this String
    if (searchEngineName.startsWith("Wik")) {
        //TODO usually only the first letter should be uppercase
        replaceStr = "_";
    } else if (searchEngineName.startsWith("DBpedia")) {
        replaceStr = "_";
    } else if (searchEngineName.startsWith("Freebase")) {
        replaceStr = "_";
        shouldBeLowerCase = true;
    } else if (searchEngineName.startsWith("Azimuth")) {
        shouldBeCapitalized = true;
    } else if (searchEngineName.startsWith("Wolfram")) { // Wolfram|Alpha
        shouldHandleMultiSelection = true;
    }
    searchTerm = splitCamelCase(searchTerm, replaceStr);
    if (shouldBeLowerCase) {
        searchTerm = searchTerm.toLowerCase();
    }
    if (shouldBeCapitalized) {
        searchTerm = searchTerm.charAt(0) + searchTerm.substring(1).toLowerCase();
    }
    if (shouldBeListOf) {
        searchTerm = listOf + replaceStr + searchTerm.toLowerCase();
    }
    if (shouldHandleMultiSelection) {
        searchTerm += handleNodeSelections(searchTermOriginal, replaceStr, searchEngineName);
    }
    String searchUrl = map.get(searchEngineName);
    if (searchUrl == null) {
        return;
    }
    searchUrl = localize(searchUrl);
    searchUrl += searchTerm;
    //consoleLog(searchUrl);
    //BrowserLauncher.launch(searchUrl); // GWT
    //consoleLog("SES searchUrl:" + searchUrl);
    if (UriUtils.isSafeUri(searchUrl)) {
        Window.open(searchUrl, "_blank", ""); // safe uri
    }
}