本文整理匯總了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();
}
示例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;
}
示例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));
}
示例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));
}
示例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 };
}
示例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;
}
示例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;
}
示例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
}
}
示例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();
}
示例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);
}
示例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;
}
示例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
}
}
示例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 };
}
示例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();
}
示例15: getMessage
import com.google.common.escape.Escaper; //導入方法依賴的package包/類
public String getMessage(Escaper escaper) {
return (null == escaper || null == message) ? message : escaper.escape(message);
}