本文整理汇总了Java中com.google.common.escape.Escaper类的典型用法代码示例。如果您正苦于以下问题:Java Escaper类的具体用法?Java Escaper怎么用?Java Escaper使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Escaper类属于com.google.common.escape包,在下文中一共展示了Escaper类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: create
import com.google.common.escape.Escaper; //导入依赖的package包/类
@Override
public Processor create ( final String configuration ) throws IllegalArgumentException
{
final FooBarConfiguration cfg = FooBarConfiguration.fromJson ( configuration );
return new Processor () {
@Override
public void process ( final Object context )
{
System.out.format ( "Foo bar: %s - %s%n", cfg.getString1 (), context );
}
@Override
public void streamHtmlState ( final PrintWriter writer )
{
final Escaper esc = HtmlEscapers.htmlEscaper ();
writer.format ( "<p>This action is doing foo bar: <code>%s</code></p>", esc.escape ( cfg.getString1 () ) );
}
};
}
示例2: getAsQuery
import com.google.common.escape.Escaper; //导入依赖的package包/类
public String getAsQuery() {
StringBuffer sb = new StringBuffer();
Escaper esc = UrlEscapers.urlFormParameterEscaper();
if (!Strings.isNullOrEmpty(asset)) {
sb.append("&asset=").append(esc.escape(asset));
}
if (startTime != null) {
sb.append("&startTime=").append(startTime.getTime());
}
if (endTime != null) {
sb.append("&endTime=").append(endTime.getTime());
}
String s = sb.toString();
return s.length() > 1 ? s.substring(1) : s; // skipping the first &
}
示例3: 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();
}
示例4: exportDatabaseAsTable
import com.google.common.escape.Escaper; //导入依赖的package包/类
/** Export as table for statistical software (R, pandas, ...) */
public void exportDatabaseAsTable() throws IOException {
List<FeedArticle> articles = getAllArticles();
BufferedWriter table = new BufferedWriter(new OutputStreamWriter(
new FileOutputStream("table.txt"), "UTF-8"));
char delimit = '\t';
// to make it readable for pandas read_table, quote strings and remove newlines
Function<String,String> strProcess = new Function<String,String>() {
private Escaper rmquote = Escapers.builder().addEscape('"', "").build();
private Escaper rmnewline = Escapers.builder().addEscape('\n', "").build();
@Override public String apply(String s) {
if (s == null) s = "";
s = rmquote.escape(s);
return new StringBuilder(s.length()+2).append('"').append(s).append('"').toString();
}
};
table.append(tableHeader(delimit)).append("\n");
for (FeedArticle art : articles) {
table.append(toTableRow(art, delimit, strProcess)).append("\n");
}
table.close();
}
示例5: 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;
}
示例6: 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));
}
示例7: 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));
}
示例8: display
import com.google.common.escape.Escaper; //导入依赖的package包/类
public void display(String rule, HttpServletResponse res) throws IOException {
res.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
res.setContentType("text/html");
res.setCharacterEncoding(UTF_8.name());
CacheHeaders.setNotCacheable(res);
Escaper html = HtmlEscapers.htmlEscaper();
try (PrintWriter w = res.getWriter()) {
w.write("<html><title>BUILD FAILED</title><body>");
w.format("<h1>%s FAILED</h1>", html.escape(rule));
w.write("<pre>");
w.write(html.escape(RawParseUtils.decode(why)));
w.write("</pre>");
w.write("</body></html>");
}
}
示例9: 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 };
}
示例10: buildUrl
import com.google.common.escape.Escaper; //导入依赖的package包/类
public static URL buildUrl(final ConnectionDetails connectionDetails, final String path, final Map<String, String> params) throws MalformedURLException {
final StringBuilder builder = new StringBuilder();
if (!connectionDetails.getEndpoint().startsWith("http")) {
builder.append(connectionDetails.isHttps() ? "https" : "http").append("://");
}
builder.append(connectionDetails.getEndpoint());
if(!path.startsWith("/")) {
builder.append('/');
}
final Escaper urlEscaper = SafeStringManipulation.getDs3Escaper();
builder.append(urlEscaper.escape(path));
if(params != null && params.size() > 0) {
builder.append('?');
builder.append(urlEscaper.escape(buildQueryString(params)));
}
return new URL(builder.toString());
}
示例11: describeOptionsHtml
import com.google.common.escape.Escaper; //导入依赖的package包/类
/**
* Returns a description of all the options this parser can digest. In addition to {@link Option}
* annotations, this method also interprets {@link OptionsUsage} annotations which give an
* intuitive short description for the options.
*/
public String describeOptionsHtml(Escaper escaper, String productName) {
StringBuilder desc = new StringBuilder();
LinkedHashMap<OptionDocumentationCategory, List<OptionDefinition>> optionsByCategory =
getOptionsSortedByCategory();
ImmutableMap<OptionDocumentationCategory, String> optionCategoryDescriptions =
OptionFilterDescriptions.getOptionCategoriesEnumDescription(productName);
for (Entry<OptionDocumentationCategory, List<OptionDefinition>> e :
optionsByCategory.entrySet()) {
desc.append("<dl>");
String categoryDescription = optionCategoryDescriptions.get(e.getKey());
List<OptionDefinition> categorizedOptionsList = e.getValue();
// Describe the category if we're going to end up using it at all.
if (!categorizedOptionsList.isEmpty()) {
desc.append(escaper.escape(categoryDescription)).append(":\n");
}
// Describe the options in this category.
for (OptionDefinition optionDef : categorizedOptionsList) {
OptionsUsage.getUsageHtml(optionDef, desc, escaper, impl.getOptionsData(), true);
}
desc.append("</dl>\n");
}
return desc.toString();
}
示例12: composeObject
import com.google.common.escape.Escaper; //导入依赖的package包/类
@Override
public void composeObject(Iterable<String> source, GcsFilename dest, long timeoutMillis)
throws IOException {
StringBuilder xmlContent = new StringBuilder(Iterables.size(source) * 50);
Escaper escaper = XmlEscapers.xmlContentEscaper();
xmlContent.append("<ComposeRequest>");
for (String srcFileName : source) {
xmlContent.append("<Component><Name>")
.append(escaper.escape(srcFileName))
.append("</Name></Component>");
}
xmlContent.append("</ComposeRequest>");
HTTPRequest req = makeRequest(
dest, COMPOSE_QUERY_STRINGS, PUT, timeoutMillis, xmlContent.toString().getBytes(UTF_8));
HTTPResponse resp;
try {
resp = urlfetch.fetch(req);
} catch (IOException e) {
throw createIOException(new HTTPRequestInfo(req), e);
}
if (resp.getResponseCode() != 200) {
throw HttpErrorHandler.error(new HTTPRequestInfo(req), resp);
}
}
示例13: 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;
}
示例14: 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;
}
示例15: 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
}
}