gpt4 book ai didi

com.github.bordertech.wcomponents.WebUtilities.escapeForUrl()方法的使用及代码示例

转载 作者:知者 更新时间:2024-03-25 16:53:05 27 4
gpt4 key购买 nike

本文整理了Java中com.github.bordertech.wcomponents.WebUtilities.escapeForUrl()方法的一些代码示例,展示了WebUtilities.escapeForUrl()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。WebUtilities.escapeForUrl()方法的具体详情如下:
包路径:com.github.bordertech.wcomponents.WebUtilities
类名称:WebUtilities
方法名:escapeForUrl

WebUtilities.escapeForUrl介绍

[英]Escapes the given string to make it presentable in a URL. This follows RFC 3986, with some extensions for UTF-8.
[中]转义给定字符串,使其在URL中可见。这是RFC 3986之后的版本,并对UTF-8进行了一些扩展。

代码示例

代码示例来源:origin: com.github.bordertech.wcomponents/wcomponents-core

/**
 * This is a slightly different version of appendGetParam that doesn't encode the ampersand seperator. It is
 * intended to be used in urls that are generated for javascript functions.
 *
 * @param key the key to append
 * @param value the value to append
 * @param vars the existing query string
 * @param existingVars true if there are already existing query string key/value pairs
 */
public static void appendGetParamForJavascript(final String key, final String value,
    final StringBuffer vars, final boolean existingVars) {
  vars.append(existingVars ? '&' : '?');
  vars.append(key).append('=').append(WebUtilities.escapeForUrl(value));
}

代码示例来源:origin: com.github.bordertech.wcomponents/wcomponents-core

/**
 * <p>
 * Appends a key/value pair to a query string.</p>
 *
 * <p>
 * A '{@literal ?}' or '{@literal &}' token will first be appended to the end of the vars StringBuffer, according to
 * the presence of other vars. We quote the '{@literal &}' using XML character entity, because otherwise the
 * resulting URL will be invalid XML parsed character data and so we can't generate XHTML.</p>
 *
 * @param key the key to append
 * @param value the value to append
 * @param vars the existing query string
 * @param existingVars true if there are already existing query string key/value pairs
 */
public static void appendGetParam(final String key, final String value,
    final StringBuffer vars, final boolean existingVars) {
  vars.append(existingVars ? "&amp;" : "?");
  vars.append(key).append('=').append(WebUtilities.escapeForUrl(value));
}

代码示例来源:origin: com.github.bordertech.wcomponents/wcomponents-core

/**
 * <p>
 * Retrieves the complete path to the theme's XSLT. This method takes the current theme and user's locale into
 * account.
 * </p>
 * <p>
 * Note: The XSLT is the single integration point to the client-side rendering.
 * </p>
 *
 * @param uic the current user's UIContext.
 * @return the theme XSLT.
 */
public static String getThemeXslt(final UIContext uic) {
  String themePath = uic.getEnvironment().getThemePath();
  StringBuffer path = new StringBuffer(themePath.length() + 20);
  // Path
  path.append(themePath);
  if (themePath.length() > 0 && !themePath.endsWith("/")) {
    path.append('/');
  }
  path.append("xslt/");
  path.append(getThemeXsltName());
  // Add cache busting suffix
  path.append("?build=").append(WebUtilities.escapeForUrl(THEME_BUILD))
      .append("&theme=").append(WebUtilities.escapeForUrl(THEME_NAME));
  return path.toString();
}

代码示例来源:origin: com.github.bordertech.wcomponents/wcomponents-core

@Test
public void testEscapeForUrl() {
  Assert.
      assertEquals("Incorrectly encoded null string", null, WebUtilities.
          escapeForUrl(null));
  Assert.assertEquals("Incorrectly encoded empty string", "", WebUtilities.escapeForUrl(""));
  Assert.
      assertEquals("Incorrectly encoded 1 char string", "x", WebUtilities.
          escapeForUrl("x"));
  Assert.assertEquals("Incorrectly encoded 1 special char string", "%20", WebUtilities.
      escapeForUrl(" "));
  // Text with multiple escapes
  String in = "Hello world slash/ question? amper& quote\" apos'";
  String expected = "Hello%20world%20slash%2f%20question%3f%20amper%26%20quote%22%20apos%27";
  Assert.assertEquals("Incorrectly escaped url", expected, WebUtilities.escapeForUrl(in));
  // Extended characters - 2 char encoding
  in = "\u0451";
  expected = "%d1%91";
  Assert.assertEquals("Incorrectly escaped url", expected, WebUtilities.escapeForUrl(in));
  // Extended characters - 3 char encoding
  in = "\u1eae";
  expected = "%e1%ba%ae";
  Assert.assertEquals("Incorrectly escaped url", expected, WebUtilities.escapeForUrl(in));
  // Extended characters - 2 and 3 char encoding
  in = "_\u0451\u1eae_";
  expected = "_%d1%91%e1%ba%ae_";
  Assert.assertEquals("Incorrectly escaped url", expected, WebUtilities.escapeForUrl(in));
}

代码示例来源:origin: com.github.bordertech.wcomponents/wcomponents-core

@Test
  public void testGetThemeXslt() {
    String themePath = "/testGetThemeXslt";
    Config.getInstance().setProperty(ConfigurationProperties.THEME_CONTENT_PATH, themePath);

    String build = ThemeUtil.getThemeBuild();
    String themeName = ThemeUtil.getThemeName();
    String versionSuffix = "?build=" + WebUtilities.escapeForUrl(build) + "&theme=" + WebUtilities.
        escapeForUrl(themeName);

    UIContext uic = createUIContext();
    Assert.assertEquals("Incorrect theme path", themePath + "/xslt/all.xsl" + versionSuffix,
        ThemeUtil.getThemeXslt(uic));

    uic.setLocale(Locale.ENGLISH);  // We used to fetch a different XSL file based on locale, this is no longer the case.
    Assert.assertEquals("Incorrect theme path", themePath + "/xslt/all.xsl" + versionSuffix,
        ThemeUtil.getThemeXslt(uic));

    uic.setLocale(Locale.CANADA_FRENCH);  // We used to fetch a different XSL file based on locale, this is no longer the case.
    Assert.assertEquals("Incorrect theme path",
        themePath + "/xslt/all.xsl" + versionSuffix, ThemeUtil.getThemeXslt(uic));
  }
}

代码示例来源:origin: com.github.bordertech.wcomponents/wcomponents-examples

+ WebUtilities.escapeForUrl("Test mailto launch"));
link5.setTargetWindowName(null);
add(link5);

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com