当前位置: 首页>>代码示例>>Java>>正文


Java Escaper.escape方法代码示例

本文整理汇总了Java中com.google.common.escape.Escaper.escape方法的典型用法代码示例。如果您正苦于以下问题:Java Escaper.escape方法的具体用法?Java Escaper.escape怎么用?Java Escaper.escape使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.common.escape.Escaper的用法示例。


在下文中一共展示了Escaper.escape方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: encodePath

import com.google.common.escape.Escaper; //导入方法依赖的package包/类
public static String encodePath(String path) {
	if (path.isEmpty() || path.equals("/")) {
		return path;
	}
	
	StringBuilder sb = new StringBuilder();
	Escaper escaper = UrlEscapers.urlPathSegmentEscaper();
	Iterable<String> iterable = pathSplitter.split(path);
	Iterator<String> iterator = iterable.iterator();
	while (iterator.hasNext()) {
		String part = iterator.next();
		if (part.isEmpty()) {
			sb.append("/");
			continue;
		}
		
		part = escaper.escape(part);
		sb.append(part);
		if (iterator.hasNext()) {
			sb.append("/");
		}
	}
	
	return sb.toString();
}
 
开发者ID:code4wt,项目名称:short-url,代码行数:26,代码来源:UrlUtils.java

示例2: add

import com.google.common.escape.Escaper; //导入方法依赖的package包/类
public Builder add ( final String label, final String targetPattern, final String... pathSegments )
{
    Objects.requireNonNull ( targetPattern );
    Objects.requireNonNull ( pathSegments );

    final Escaper esc = UrlEscapers.urlPathSegmentEscaper ();

    final Object[] encoded = new String[pathSegments.length];
    for ( int i = 0; i < pathSegments.length; i++ )
    {
        encoded[i] = esc.escape ( pathSegments[i] );
    }

    this.entries.add ( new Entry ( label, MessageFormat.format ( targetPattern, encoded ) ) );
    return this;
}
 
开发者ID:eclipse,项目名称:packagedrone,代码行数:17,代码来源:Breadcrumbs.java

示例3: uiReportMentionValueOccurrences

import com.google.common.escape.Escaper; //导入方法依赖的package包/类
private void uiReportMentionValueOccurrences(final Map<String, Object> model,
        final URI entityID, @Nullable final URI property) throws Throwable {

    // Do nothing in case the entity ID is missing
    if (entityID == null || property == null) {
        return;
    }

    // Compute the # of occurrences of all the values of the given property in entity mentions
    final Multiset<Value> propertyValues = HashMultiset.create();
    for (final Record mention : getEntityMentions(entityID, Integer.MAX_VALUE, null)) {
        propertyValues.addAll(mention.get(property, Value.class));
    }

    // Render the table
    final Escaper esc = UrlEscapers.urlFormParameterEscaper();
    final String linkTemplate = "ui?action=entity-mentions&entity="
            + esc.escape(entityID.stringValue()) + "&property="
            + esc.escape(Data.toString(property, Data.getNamespaceMap()))
            + "&value=${element}";
    model.put("valueOccurrencesTable", RenderUtils.renderMultisetTable(new StringBuilder(),
            propertyValues, "Property value", "# Mentions", linkTemplate));
}
 
开发者ID:dkmfbk,项目名称:knowledgestore,代码行数:24,代码来源:Root.java

示例4: uiReportMentionPropertyOccurrences

import com.google.common.escape.Escaper; //导入方法依赖的package包/类
private void uiReportMentionPropertyOccurrences(final Map<String, Object> model,
        final URI entityID) throws Throwable {

    // Do nothing in case the entity ID is missing
    if (entityID == null) {
        return;
    }

    // Compute the # of occurrences of each property URI in entity mentions
    final Multiset<URI> propertyURIs = HashMultiset.create();
    for (final Record mention : getEntityMentions(entityID, Integer.MAX_VALUE, null)) {
        propertyURIs.addAll(mention.getProperties());
    }

    // Render the table
    final Escaper esc = UrlEscapers.urlFormParameterEscaper();
    final String linkTemplate = "ui?action=entity-mentions&entity="
            + esc.escape(entityID.stringValue()) + "&property=${element}";
    model.put("propertyOccurrencesTable", RenderUtils.renderMultisetTable(new StringBuilder(),
            propertyURIs, "Property", "# Mentions", linkTemplate));
}
 
开发者ID:dkmfbk,项目名称:knowledgestore,代码行数:22,代码来源:Root.java

示例5: transform

import com.google.common.escape.Escaper; //导入方法依赖的package包/类
@Override
public String[] transform(final InputRow inputRow) {
    final String value = inputRow.getValue(column);
    if (value == null) {
        return new String[1];
    }
    final Escaper escaper;
    switch (targetFormat) {
    case FORM_PARAMETER:
        escaper = UrlEscapers.urlFormParameterEscaper();
        break;
    case FRAGMENT:
        escaper = UrlEscapers.urlFragmentEscaper();
        break;
    case PATH_SEGMENT:
        escaper = UrlEscapers.urlPathSegmentEscaper();
        break;
    default:
        throw new UnsupportedOperationException();
    }
    final String escaped = escaper.escape(value);
    return new String[] { escaped };
}
 
开发者ID:datacleaner,项目名称:DataCleaner,代码行数:24,代码来源:UrlEncoderTransformer.java

示例6: getPathAndQuery

import com.google.common.escape.Escaper; //导入方法依赖的package包/类
public String getPathAndQuery() {
  String url = this.path;
  boolean isFirst = true;
  for (Map.Entry<String, String> queryParameter : this.queryParameters.entries()) {
    if (isFirst) {
      url += "?";
      isFirst = false;
    } else {
      url += "&";
    }
    Escaper escaper = UrlEscapers.urlFormParameterEscaper();
    url += escaper.escape(queryParameter.getKey()) + "=" + escaper.escape(queryParameter.getValue());
  }

  return url;
}
 
开发者ID:HuygensING,项目名称:timbuctoo,代码行数:17,代码来源:HttpRequest.java

示例7: getPathAndQuery

import com.google.common.escape.Escaper; //导入方法依赖的package包/类
public String getPathAndQuery() {

    String url = this.path;
    boolean isFirst = true;
    for (Map.Entry<String, String> queryParameter : this.queryParameters.entries()) {
      if (isFirst) {
        url += "?";
        isFirst = false;
      } else {
        url += "&";
      }
      Escaper escaper = UrlEscapers.urlFormParameterEscaper();
      url += escaper.escape(queryParameter.getKey()) + "=" + escaper.escape(queryParameter.getValue());
    }

    return url;
  }
 
开发者ID:HuygensING,项目名称:timbuctoo,代码行数:18,代码来源:HttpRequest.java

示例8: assertBasic

import com.google.common.escape.Escaper; //导入方法依赖的package包/类
/**
 * Asserts that an escaper behaves correctly with respect to null inputs.
 *
 * @param escaper the non-null escaper to test
 */
public static void assertBasic(Escaper escaper) throws IOException {
  // Escapers operate on characters: no characters, no escaping.
  Assert.assertEquals("", escaper.escape(""));
  // Assert that escapers throw null pointer exceptions.
  try {
    escaper.escape((String) null);
    Assert.fail("exception not thrown when escaping a null string");
  } catch (NullPointerException e) {
    // pass
  }
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:17,代码来源:EscaperAsserts.java

示例9: toQueryString

import com.google.common.escape.Escaper; //导入方法依赖的package包/类
/** Returns this SolrParams as a properly URL encoded string, starting with {@code "?"}, if not empty. */
public String toQueryString() {
    Escaper escaper = UrlEscapers.urlFragmentEscaper();

    final StringBuilder sb = new StringBuilder(128);
    boolean first = true;
    for (final Iterator<String> it = getParameterNamesIterator(); it.hasNext();) {
        final String name = it.next(), nameEnc = escaper.escape(name);
        for (String val : getParams(name)) {
            sb.append(first ? '?' : '&').append(nameEnc).append('=').append(escaper.escape(val));
            first = false;
        }
    }
    return sb.toString();
}
 
开发者ID:LIBCAS,项目名称:ARCLib,代码行数:16,代码来源:SolrParams.java

示例10: formatReportUrl

import com.google.common.escape.Escaper; //导入方法依赖的package包/类
@VisibleForTesting
static String formatReportUrl() {
  String body = MessageFormat.format(BODY_TEMPLATE, CloudToolsInfo.getToolsVersion(),
      getCloudSdkVersion(), getEclipseVersion(),
      System.getProperty("os.name"), System.getProperty("os.version"),
      System.getProperty("java.version"));

  Escaper escaper = UrlEscapers.urlFormParameterEscaper();
  return BUG_REPORT_URL + "?body=" + escaper.escape(body);
}
 
开发者ID:GoogleCloudPlatform,项目名称:google-cloud-eclipse,代码行数:11,代码来源:BugReportCommandHandler.java

示例11: renderMultisetTable

import com.google.common.escape.Escaper; //导入方法依赖的package包/类
public static <T extends Appendable> T renderMultisetTable(final T out,
        final Multiset<?> multiset, final String elementHeader,
        final String occurrencesHeader, @Nullable final String linkTemplate)
        throws IOException {

    final String tableID = "table" + COUNTER.getAndIncrement();
    out.append("<table id=\"").append(tableID).append("\" class=\"display datatable\">\n");
    out.append("<thead>\n<tr><th>").append(MoreObjects.firstNonNull(elementHeader, "Value"))
            .append("</th><th>")
            .append(MoreObjects.firstNonNull(occurrencesHeader, "Occurrences"))
            .append("</th></tr>\n</thead>\n");
    out.append("<tbody>\n");
    for (final Object element : multiset.elementSet()) {
        final int occurrences = multiset.count(element);
        out.append("<tr><td>");
        RenderUtils.render(element, out);
        out.append("</td><td>");
        if (linkTemplate == null) {
            out.append(Integer.toString(occurrences));
        } else {
            final Escaper esc = UrlEscapers.urlFormParameterEscaper();
            final String e = esc.escape(Data.toString(element, Data.getNamespaceMap()));
            final String u = linkTemplate.replace("${element}", e);
            out.append("<a href=\"").append(u).append("\">")
                    .append(Integer.toString(occurrences)).append("</a>");
        }
        out.append("</td></tr>\n");
    }
    out.append("</tbody>\n</table>\n");
    out.append("<script>$(document).ready(function() { applyDataTable('").append(tableID)
            .append("', false, {}); });</script>");
    return out;
}
 
开发者ID:dkmfbk,项目名称:knowledgestore,代码行数:34,代码来源:RenderUtils.java

示例12: assertBasic

import com.google.common.escape.Escaper; //导入方法依赖的package包/类
/**
 * Asserts that an escaper behaves correctly with respect to null inputs.
 *
 * @param escaper the non-null escaper to test
 * @throws IOException
 */
public static void assertBasic(Escaper escaper) throws IOException {
  // Escapers operate on characters: no characters, no escaping.
  Assert.assertEquals("", escaper.escape(""));
  // Assert that escapers throw null pointer exceptions.
  try {
    escaper.escape((String) null);
    Assert.fail("exception not thrown when escaping a null string");
  } catch (NullPointerException e) {
    // pass
  }
}
 
开发者ID:sander120786,项目名称:guava-libraries,代码行数:18,代码来源:EscaperAsserts.java

示例13: transform

import com.google.common.escape.Escaper; //导入方法依赖的package包/类
@Override
public String[] transform(final InputRow inputRow) {
    final String value = inputRow.getValue(column);
    if (value == null) {
        return new String[1];
    }
    final Escaper escaper;
    if (targetFormat == TargetFormat.Content) {
        escaper = XmlEscapers.xmlContentEscaper();
    } else {
        escaper = XmlEscapers.xmlAttributeEscaper();
    }
    final String escaped = escaper.escape(value);
    return new String[] { escaped };
}
 
开发者ID:datacleaner,项目名称:DataCleaner,代码行数:16,代码来源:XmlEncoderTransformer.java

示例14: encodeQuery

import com.google.common.escape.Escaper; //导入方法依赖的package包/类
public static String encodeQuery(String query) {
	Escaper escaper = UrlEscapers.urlFormParameterEscaper();
	StringBuilder sb = new StringBuilder();
	
	Iterable<String> keyValueIterable = querySplitter.split(query);
	Iterator<String> iterator = keyValueIterable.iterator();
	while(iterator.hasNext()) {
		String keyValue = iterator.next();
		if (keyValue.isEmpty()) {
			if (iterator.hasNext()) {
				sb.append("&");
			}
			continue;
		}
		
		if (keyValue.equals("=")) {
			sb.append(keyValue);
			if (iterator.hasNext()) {
				sb.append("&");
			}
			continue;
		}
		
		int index = keyValue.indexOf('=');
		if (index == -1) {
			keyValue = escaper.escape(keyValue);
			sb.append(keyValue);
			if (iterator.hasNext()) {
				sb.append("&");
			}
			continue;
		}
		
		String key = keyValue.substring(0, index);
		if (index == 0) {
			key = "";
		}
		String value = "";
		if (index + 1 < keyValue.length()) {
			value = keyValue.substring(index + 1, keyValue.length());
		}
		
		if (!key.isEmpty()) {
			key = escaper.escape(key);
			sb.append(key);
			sb.append("=");
		}
		if (!value.isEmpty()) {
			value = escaper.escape(value);
			sb.append(value);
			if (iterator.hasNext()) {
				sb.append("&");
			}
		}
	}
	
	return sb.toString();
}
 
开发者ID:code4wt,项目名称:short-url,代码行数:59,代码来源:UrlUtils.java

示例15: getMessage

import com.google.common.escape.Escaper; //导入方法依赖的package包/类
public String getMessage(Escaper escaper) {
	return (null == escaper || null == message) ? message : escaper.escape(message);
}
 
开发者ID:nmdp-bioinformatics,项目名称:service-epitope,代码行数:4,代码来源:ExceptionMapper.java


注:本文中的com.google.common.escape.Escaper.escape方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。