當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。